[Android Notes] basic usage of notification and icationicationmanager

Source: Internet
Author: User

1. icationicationmanager and notification are used to set notifications.

The notification setting and other operations are relatively simple. The basic method is to create a notification object and set the notification parameters, then, use the icationicationmanager service running in the system background to send the notification.

The basic steps are as follows:

1) Obtain icationicationmanager:

String NS = context. icationication_service;

Icationicationmanager mnotificationmanager = (notificationmanager) getsystemservice (NS );

2) create a new notification object:

Notification = new notification ();

Notification. Icon = R. drawable. icationication_icon;

You can also create a notification in a slightly more complex way:

Int icon = R. drawable. icationication_icon; // notification icon

Charsequence tickertext = "hello"; // notification text prompt displayed in the status bar

Long when = system. currenttimemillis (); // the time when a notification is generated. It is displayed in the notification information.

Notification = new notification (icon, tickertext, when );

3) Fill in the attributes of notification:

Context context = getapplicationcontext ();

Charsequence contenttitle = "my notification ";

Charsequence contenttext = "Hello world! ";

Intent icationicationintent = new intent (this, myclass. Class );

Pendingintent contentintent = pendingintent. getactivity (this, 0, icationicationintent, 0 );

Notification. setlatesteventinfo (context, contenttitle, contenttext, contentintent );

Notification provides a wide range of mobile phone prompts:

A) notification text prompts displayed in the status bar, such:

Notification. tickertext = "hello ";

B) make a prompt, for example:

Notification. defaults | = notification. default_sound;

Notification. Sound = URI. parse ("file: // sdcard/notification/ringer.pdf ");

Notification. Sound = URI. withappendedpath (audio. Media. internal_content_uri, "6 ");

C) Mobile Phone vibration, such:

Notification. defaults | = notification. default_vibrate;

Long [] vibrate = {0,100,200,300 };

Notification. vibrate = vibrate;

D) LED light flashes, such:

Notification. defaults | = notification. default_lights;

Notification. ledargb = 0xff00ff00;

Notification. ledonms = 300;

Notification. ledoffms = 1000;

Notification. Flags | = notification. flag_show_lights;

4) send notifications:

Private Static final int id_notification = 1;

Micationicationmanager. Y (id_notification, notification );

2. update notifications

To update a notification, you only need to call setlatesteventinfo after setting the notification, and then resend the notification.

3. Custom Notification View

For details about this part, refer to the official documentation.

Androidsdk: docs/GUIDE/topics/UI/notifiers/icationications.html

Reference:

Androidsdk1.5: docs/GUIDE/topics/UI/notifiers/icationications.html

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.