How to Implement the Android Message notification bar

Source: Internet
Author: User

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.
Effect:

Code:
Copy codeThe Code is as follows: // Message notification bar
// Define icationicationmanager
String ns = Context. icationication_service;
Icationicationmanager mNotificationManager = (NotificationManager) getSystemService (ns );
// Define the content displayed in the notification bar
Int icon = R. drawable. icon;
CharSequence tickerText = "my notification bar title ";
Long when = System. currentTimeMillis ();
Notification notification = new Notification (icon, tickerText, when );

// Define the content to be displayed in the drop-down notification bar
Context context = getApplicationContext ();
CharSequence contentTitle = "Expand the title of my notification bar ";
CharSequence contentText = "detail 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 );

// Notify the user to generate a title bar Message notification using the notify method of micationicationmanager
Micationicationmanager. Y (1, notification );

Related Article

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.