Notification
Can be used to display icons and information on the status bar, to blink LEDs, vibrate phones, ringtones or music reminders, display additional information, and use interactive controls.
Notification Manageris used to
Management Notification, including
triggers a new notification, modifies the existing, cancels the notifications.
NotificationManager常用方法介绍:
Display method
public
void
notify(
int
id, Notification notification) 将通知加入状态栏,标记为id
public
void
notify(String tag ,
int
id, Notification notification) 将通知加入状态栏,标签为tag,标记为id
Purge method
public
void
cancel(
int
id) 移除标记为id的通知 (只是针对当前Context下的所有Notification)
public
void
cancelAll() 移除所有通知(只是针对当前Context下的Notification)
Core code:
//to create a Notificationmanager referenceNotificationmanager Notificationmanager =(Notificationmanager) This. Getsystemservice (Android.content.Context.NOTIFICATION_SERVICE); //defining various properties of the notificationNotification Notification =NewNotification (R.drawable.icon_luncher,Notification, System.currenttimemillis ()); //FLAG_AUTO_CANCEL This notification can be cleared by the purge button of the status bar//flag_no_clear The notification cannot be cleared by the Purge button in the status bar//flag_ongoing_event notifications are placed in the running//whether the flag_insistent is always on, such as music always playing, know user responseNotification.flags |= notification.flag_ongoing_event;//place this notification in the "ongoing" or "running" Group of the notification barNotification.flags |= notification.flag_no_clear;//indicates that this notification is not cleared and is often used with flag_ongoing_event when you click Clear Notification in the notification barNotification.flags |=notification.flag_show_lights; //Default_all use all default values, such as sound, vibration, splash screen, etc.//default_lights using default flash hints//default_sounds using default cue sound//default_vibrate Use default phone shake, add <uses-permission android:name= "Android.permission.VIBRATE"/> PermissionsNotification.defaults =notification.default_lights; //Overlay Effect Constants//notification.defaults=notification.default_lights| Notification.default_sound;Notification.ledargb =Color.Blue; Notification.ledonms= 5000;//flash time, milliseconds//set event messages for notificationsCharsequence Contenttitle = "I am the title";//Notification Bar HeaderCharsequence ContentText = "I am content";//Notification Bar ContentsIntent notificationintent =NewIntent (mainactivity. This, Mainactivity.class);//activity to jump after clicking on the notificationPendingintent contentitent = pendingintent.getactivity ( This, 0, notificationintent, 0); Notification.setlatesteventinfo ( This, Contenttitle, ContentText, contentitent); //Pass the notification to Notificationmanager .Notificationmanager.notify (0, notification);
Clear notifications:
// Clear Notification Notificationmanager nm = (Notificationmanager) Getsystemservice (Notification_service); Nm.cancel (0); the number 0 is the same identifier that is cleared and the identifier displayed
Note: The purge action is usually cleared before entering the specified page and can be performed in Onresume () or OnStart ().
Alumni Profile: http://my.oschina.net/wangjunhe/blog/113855
Android Notification Notification Learning 123