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