Android status bar notification

Source: Internet
Author: User

For Android Developers, they always hope that the programs they develop can be frequently used by users, so the most important thing is to directly access the programs where users can see them... The status bar notification is like this, such as QQ, 360, or other IM software.

So how to implement status bar notification?

A simple way to do this:

// Message Manager
Private icationicationmanager n_icationicationmanager;
Private pendingintent n_pendingintent;
// Notification object
Private notification n_notification;

Public void shownotification (INT dwrid)
{
// Initialize the message Manager
N_icationicationmanager = (notificationmanager) getsystemservice (notification_service );


// Set the page for displaying the content when you click the notification.
N_pendingintent = pendingintent. getactivity (icityactivity. This, 0, getintent (), 0 );


// Notification object
N_notification = new notification ();


// Set the icon of the notification displayed in the status bar
N_icationication.icon = dwrid;


// Content displayed when we click the notification
N_notification.tickertext = "Akemi is starting cosmic-level equipment. Please wait .....";


// Send the default sound during notification
N_notification.defaults = notification. default_sound;


// Set the notification display parameters
N_icationication.setlatesteventinfo (icityactivity. This, "Akemi", "Akemi, bringing you infinite happiness", n_pendingintent );


// It can be understood as executing this notification
N_notificationmanager.policy (0, n_notification );

}

Call the activity when it is started, and give the icon ID

Remember:

Protected void ondestroy (){


// Clear it
N_notificationmanager.cancelall ();
Super. ondestroy ();


}

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.