Chapter 2 notification and status bar Information

Source: Internet
Author: User

To create and display a notification:

1. Get a icationicationmanager object through the getsystemservice Method

-- Icationicationmanager = (notificationmanager) getsystemmanager (icationication_service );

2. Create a notification object. Each notification corresponds to a notification object. In this step, you need to set the notification information displayed at the top of the screen, the image resource ID in front of the notification message, and the time when the notification is sent, which is generally the current time.

-- Notification = new notification (R. drawable. Icon, "you have new information", system. currenttimemillis ());

3. Notification can be detached from the application. That is to say, even if the application is closed, the notification will be displayed in the status bar. After the program starts, you can re-control these notifications, such as clear or replace them. Therefore, you must create a pendingintent object. This object is maintained by the Android system. Therefore, after the application is closed, the object cannot be released.

-- Pendingintent contentintent = getactivity (this, 0, getintent (), 0 );

4. Use the setlateseventinfo method of the notification class to set notification details.

Notificatio. setlateseventinfo (this, "Weather Forecast", "Clear to cloudy", contentintent );

5. Use the y icationmanager class's notify y method to display notification information. In this example, you must specify the unique ID that identifies notification. This ID must be unique relative to the same notificationmanager object. Otherwise, the same notification will be overwritten.

-- Icationicationmanager. Y (R. drawable. Icon, 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.