Created
April 22, 2015 03:40
-
-
Save Aiur3908/33339b47b37513a1bef3 to your computer and use it in GitHub Desktop.
sendNotification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void sendNotification() | |
{ | |
int notificationId = 001; | |
//決定這個notification的辨識編號 | |
Intent mapIntent = new Intent(Intent.ACTION_VIEW); | |
//建立Intent , 這次改ACTION_VIEW | |
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("台北火車站")); | |
//建立一個Uri,假設要找台北火車站。 | |
mapIntent.setData(geoUri); | |
//設定資料 | |
PendingIntent mapPendingIntent = | |
PendingIntent.getActivity(this, 0, mapIntent, 0); | |
//使用PendingIntent來等待執行這個intent | |
NotificationCompat.Action action = new NotificationCompat.Action.Builder | |
(R.drawable.ic_launcher , "Map" , mapPendingIntent).build(); | |
//建立一個NotificationCompat.Action物件,透過Builder來建立,並填入圖片,說明及PendingIntent | |
NotificationCompat.Builder notificationBuilder = | |
new NotificationCompat.Builder(this) | |
.setSmallIcon(R.drawable.pika) | |
.setLargeIcon(BitmapFactory.decodeResource( | |
getResources(), R.drawable.nbg)) | |
.setContentTitle("Title") | |
.setContentText("內容") | |
.extend(new NotificationCompat.WearableExtender().addAction(action)); | |
//使用setLargeIcon來設定背景圖片 | |
NotificationManagerCompat notificationManager = | |
NotificationManagerCompat.from(this); | |
//取得NotificationManagerCompat的實體 | |
notificationManager.notify(notificationId, notificationBuilder.build()); | |
//填入辨識編號及notification後,即可發送出去 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment