Android Apidemos Sample Resolution: App->notification->incomingmessage

Source: Internet
Author: User

The application can use notifications to notify the user that an event has occurred (such as receiving a text message). Class Notificationmanager is used to process Notification, Notificationmanager can:

A new icon is displayed on the status bar.

Displays additional information on the Extended Status bar window or initiates an activity.

Displays the backlight/led.

Vibrate the equipment.

Make a sound and so on.

For some application components that do not have a UI (such as broadcast Receiver, Services) or inactive activity,notification is a recommended method to alert the user.

Notification usually displays an icon or text on the status bar, when the user wants to know the details of notification, you can hold down the status bar Drop-down to display the Expanded Status bar window, in expanded The Status Bar window displays the notification details and can initiate the corresponding activity.

The Incomingmessage sample describes the general usage of notification:

1. The first is the acquisition of Notificationmanager objects:

Notificationmanager nm     
= (Notificationmanager) getsystemservice (Notification_service);

2. Then create the notification, when you create the notification, specify the icon to display in the status bar, the text, and the time to display the notification:

Notification Notif = new Notification

(R.drawable.stat_sample, Tickertext,     
System.currenttimemillis ());

3. Then define the caption and details when the user opens the Extented Status Windows window. Notification often represents a request or event that requires attention, so you can specify a pendingintent to respond to the user clicking on the Notification.

The details of our fake message     
charsequence from = "Joe";     
Charsequence message = "kthx." Meet u for dinner. Cul8r ";     
          
The pendingintent to launch we activity if the user selects this notification     
pendingintent contentintent = Pendin Gintent.getactivity (this, 0, the     
new Intent (this, incomingmessageview.class), 0);     
Set the info for the "views" of the notification panel.     
Notif.setlatesteventinfo (this, from, message, contentintent);     
After the a 100ms delay, vibrate for 250ms, pause for MS and     
//then vibrate for 500ms.     
Notif.vibrate = new long[] {100, 250, 100, 500};

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.