Android Notification introduction, androidnotification
To add a Notification, follow these steps:
1: Obtain icationicationmanager:
Icationicationmanager m_NotificationManager = (NotificationManager) this. getSystemService (icationication_service );
2: Define a Notification:
Notification m_Notification = new Notification ();
3: set various attributes of Notification:
// Set the icon m_icationication.icon = R. drawable. icon displayed in the status bar;
// The content displayed when we click notification m_icationication.tickertext = "Button1 notification content .....";
Default sound m_icationication.defaults = Notification. DEFAULT_SOUND;
// Set the notification display parameters
Intent m_Intent = new Intent (icationicationdemo. this, DesActivity. class); PendingIntent m_PendingIntent = PendingIntent. getActivity (icationicationdemo. this, 0, m_Intent, 0 );
M_icationication.setlatesteventinfo (icationicationdemo. this, "Button1", "Button1 notification", m_PendingIntent );
// This can be understood as starting to execute the notification m_icationicationmanager.y y (0, m_Notification );
4: Now that you can add or delete it. Of course, it is just to delete what you add.
M_icationicationmanager.cancel (0 );
Here 0 is an ID number, which is the same as the first parameter 0 of policy.
This completes adding and deleting.
NoticificationManager can be easily placed in the status bar, and it is easy to access the program from statusbar. NoticificationManager can execute the activity of this program through intent.
NoticificationManager status bar operation
Icationicationmanager: notifies users of an event. icationicationmanager has three common methods: 1. cancel (int id) cancels a previously displayed notification. for example, a short notification tries to hide it. For example, a persistent notification will be removed from the status bar. 2. cancelAll () cancels all previously displayed notifications. 3. Y (int id, Notification) permanently sends the notification to the status bar.
// Initialize icationicationmanager: icationicationmanager nm = (NotificationManager) getSystemService (icationication_service );
Notification indicates a Notification. notification attributes: audioStreamType when the sound rings, the type of the audio stream contentIntent used. When the Notification entry is clicked, the configured Intent is executed. contentView: When a notification is displayed on the status bar, the configured view is also displayed. defaults specifies the value to be set to the default value. deleteIntent when you click the "Clear All Notifications" button to delete All Notifications, the configured Intent is executed. the image used by the icon status bar. iconLevel if there are several levels of Status Bar images, set it here. ledARGB LED light color. flash time when ledOffMS LED is disabled (in milliseconds) Flash time when ledOnMS LED starts (in milliseconds) number indicates the voice of the event number sound notification. When the tickerText notification is displayed in the status bar, the information is displayed in vibrate vibration mode. the timestamp of the when notification.
Send Notification to the status bar: Notification notification = new Notification (); Notification setting process ........ Nm. Y (0, notification); // it is sent to the status bar.
Bytes ------------------------------------------------------------------------------------------------------------
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 );