Background Knowledge: You can use activity and service to start Message notification. The difference between the two is that one is triggered at the foreground, and the other is triggered by the background service. To use Message notification, you must use two classes: icationicationmanager and notification. For initialization of other notificationmanager, The getsystemservice method is used, and the y method is used to send message bar notifications and display to the Android system. Code : // Notification bar // define icationicationmanagerstring NS = context. notification_service; notificationmanager micationicationmanager = (notificationmanager) getsystemservice (NS); // defines the content displayed in the notification bar. Int icon = R. drawable. icon; charsequence tickertext = "my notification bar title"; long when = system. currenttimemillis (); Notification = new notification (icon, tickertext, when); // defines the content to be displayed in the drop-down notification bar. Context context = getapplicationcontext (); charsequence contenttitle = "show title in my notification bar"; charsequence contenttext = "Show Details in my notification bar"; intent icationicationintent = new intent (this, bootstartdemo. class); pendingintent contentintent = pendingintent. getactivity (this, 0, icationicationintent, 0); notification. setlatesteventinfo (context, contenttitle, contenttext, contentintent); // use the notify method of micationicationmanager to notify the user to generate a title bar message and notify mnotificationmanager. Y (1, notification );
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.