1. Communications
A notification is a message you can display to the user outside of your application's normal UI. When you tell the system to issue
Notification, it first appears as an icon inNotification area. To see the details of the notification, the user opensNotification
Drawer.
<1> events in the notification area
<2> Noticafications in the notification drawer
2. Notification Display Elements
<1> Normal View
1 ---> Content title
2 ---> Large icon
3 ---> Content text
4 ---> Content info
5 ---> Small icon
6 ---> Time that the notification was issued. set an explicit value with setWhen ()
If you don't if defaults to the time that the system has ed the notification
<2> Big View
A notification's big view appears only when the notification is expanded,
Which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture.
Expanded events are available starting with Android 4.1.
3. Creating a Notification
3.1 Required notification contents
Must contain the following: icon (setSmallIcon (), title (setContentTitle (), text (setContentText ())
3.2 Notification priority
The priority acts as a hint to the device UI about how the notification shocould be displayed.
SetPriority () pass in one of the icationicationcompat priority constants.
There are five priority levels, ranging from PRIORITY_MIN (-2) to PRIORITY_MAX (2), if not set, defaults to PRIORITY_DEAFAULT (0)
3.3 Creating a simple notification
Protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_icationication_test); Builder mBuilder = new Notification. builder (this ). setSmallIcon (R. drawable. mail ). setContentTitle ("Mymail "). setContentText ("Hello World! ")
. SetTicker ("You have an new message"); icationicationmanager micationicationmanager = (icationicationmanager) getSystemService (Context. NOTIFICATION_SERVICE); // Id allows you to update the notification later on. micationicationmanager. notify (0, mBuilder. build ());}
3.4 Big View style notification
Icationicationmanager mNotificationManager = (NotificationManager) getSystemService (Context. NOTIFICATION_SERVICE); InboxStyle inboxStyle = new InboxStyle (); inboxStyle. setBigContentTitle ("5 news messages"); inboxStyle. addLine ("message 1"); inboxStyle. addLine ("message 2"); inboxStyle. addLine ("message 3"); inboxStyle. addLine ("message 4"); inboxStyle. addLine ("message 5"); Builder mBuilder = new Notifica Tion. Builder (this). setSmallIcon (R. drawable. mail). setContentTitle ("Mymail"). setContentText ("Hello World! "). SetTicker ("You have an new message "). setPriority (Notification. PRIORITY_DEFAULT ). setDefaults (Notification. DEFAULT_VIBRATE ). setStyle (inboxStyle); // Id allows you to update the notification later on. micationicationmanager. notify (0, mBuilder. build ());
4. Manageing Communications
4.1 Updating specifications
To set up a notification so it can be updated, issue it with a notification ID by calling
Icationicationmanager. notify (ID, notification)
To update this notification once you 've issued it, issue the Notification with the same ID you used previously.
If the previous notification is still visible, the system updates it. otherwise, create a new notification instead.
4.2 Removing specifications
Dismiss the notification either individually or "clear all" (if notification can be cleared) by calling cancel () and cancelAll ()
User clicks the notification, you can call setAutoCancel when created the notification
5. Preserving Navigation when Starting an activity
Two general situations:
<1> Regular activity
Events from the Gmail app demonstrate this.
When you click a notification for a single email message, you see the message itself. TouchingBackTakes you backwards through
Gmail to the Home screen, just as if you had entered Gmail from the Home screen rather than entering it from a notification.
You are starting an Activity that's part of the application's normal workflow. In this situation, set up
PendingIntent to start
Fresh task, and provider the PendingIntent with a back stack thta reproduces the application's normal BACK behavior
<2> Special activity
The user only sees this
Activity if it is started from a notification
5.1 Setting up a regular activity PendingIntent
6. Displaying Progress in aNotification
An animated progress indicator that shows the status of an ongoing operation
Determanate form of the indicator (a progress bar)
Indeterminate form of the indicator (an activity indicator)
6.1 a fixed-duration progress indicator
Private Builder mBuilder; private icationicationmanager micationicationmanager; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_icationication_test); mNotificationManager = (NotificationManager) getSystemService (Context. NOTIFICATION_SERVICE); mBuilder = new Notification. builder (this ). setSmallIcon (R. drawable. mail ). setContentTitle ("Picture Download "). setContentText ("Download in progress"); new Thread (new Runnable () {@ Override public void run () {for (int I = 0; I <100; I ++) {// Sets the progress indicator to a max value, the current completion percentage, // and "determinate" state mBuilder. setProgress (100, I, false); micationicationmanager. notify (1, mBuilder. build (); try {Thread. sleep (5*100);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace () ;}// When the loop is finished, updates the notification mBuilder. setContentText ("Download complete") // Removes the progress bar. setProgress (0, 0, false); micationicationmanager. notify (1, mBuilder. build ());}}). start ();}
6.2 a continuing activity indicator
MBuilder. setProgress (100, I, false );
Http://blog.csdn.net/vipzjyno1/article/details/25248021
5. User Interface/Notifications