Android Notification Notification Learning 123

Source: Internet
Author: User

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,标记为idPurge 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.