Introduction to the implementation method of the ANDROID message notification bar _android

Source: Internet
Author: User
Background: You can start a message notification with activity and service, the difference being that one is triggered in the foreground and one is the background service.
To use message notifications, you must use two classes: NotificationmanagerAnd Notification, other notificationmanager are initialized with the Getsystemservice method, and the Notify method is used to send Message bar notifications and displays to the Android system.
Effect:

Code:
Copy Code code as follows:

Message Notification Bar
Define Notificationmanager
String ns = Context.notification_service;
Notificationmanager Mnotificationmanager = (notificationmanager) getsystemservice (NS);
Define the content information displayed by the notification bar
int icon = R.drawable.icon;
Charsequence Tickertext = "My notice bar title";
Long when = System.currenttimemillis ();
Notification Notification = new Notification (icon, Tickertext, when);

Define the content information to be displayed when the DROP-DOWN notification bar is defined
Context context = Getapplicationcontext ();
Charsequence Contenttitle = "My notice bar expands title";
Charsequence ContentText = "My notice bar expands the details";
Intent notificationintent = new Intent (this, bootstartdemo.class);
Pendingintent contentintent = pendingintent.getactivity (this, 0,
Notificationintent, 0);
Notification.setlatesteventinfo (context, Contenttitle, ContentText,
Contentintent);

Notifies the user to generate a title bar message notification using the Mnotificationmanager notify method
Mnotificationmanager.notify (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.