2012年11月7日 星期三

[Android] Notification

Notification是指畫面上方資訊列的訊息提示

//先取出Notification管理員
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
//產生一個Notification
 Notification notification= new Notificatio( R.deawable.icon, "This is Message", System.currentTimeMills());
//建立Intent
Intent intent = new Intent(context,ActivityName.class);
//建立PendingIntent
 PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent ,0);

//設定 Notification內容
 notification.setLatestEventInfo(context,"This is Title","This is Message",pendingIntent);
//發送 Notification
 notificationManager.notify(0,notification);