Use of Android notification and Notificationmanager

Source: Internet
Author: User

Notification and Notificationmanager

The 1.Broadcast Receiver component does not provide a visual interface to display broadcast information. Here we can use notification and Notificationmanager to visualize the information display. By using them we can display the contents of the broadcast message, the icon

and vibration and other information.

2. The use of notification and Notificationmanager is also relatively simple, generally obtain a system-level service Notificationmanager, and then instantiate notification, set its properties, It is possible to send a notice via Notificationmanager.

The basic steps are as follows:

1) obtain system-level service Notificationmanager, here is relatively simple, through the Context.getsystemservice () method can be achieved.

1 String service = Notification; 2 notificationmanager nm = (notificationmanager) getsystemservice (service);

2) Instantiate the notification object and set its properties.

// Instantiate notification New Notification (); // Who knows the display icon, the icon will appear in the status bar int icon = N.icon = R.drawable.icon; // Set the display prompt message, String tickrttext = "Test Notification"; // Show Time long when == = when;

3) Call the Setlatestecentinfo () method to set the icon and time in the view

Instantiate intent

New Intent (This, mainactivity.  Class); // Get Pendingintent pendingintent  pi = pendingintent  . getactivity (This, 0,intent,0); // Set Time information n.setlasteventinfo (This, "My content", "My Content", pi);

4) Giving Notice

// represents the ID of the notification int ID = 1; // notification nm.notify (id,n);

3. The following is a direct example of how

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.