Notice
Android and Apple, after the app in the background, when you need to send some messages to the customer to notify the things such as to use to inform this thing, Android notice is obviously more simple than Apple, Apple in the notice of the main display in the remote push and local notifications above, Here we simply talk about the local Android notification and the basic display, remote push things in the back of the time to do a summary, first look at the following one run, this is my own Android test machine to see the effect, the other there is nothing to say, What you need to be aware of in the code is clearly documented in the code comments, directly on the code:
Notice
Note Here the difference between pendingintent and intent, intent more prone to immediate action//pendingintent more inclined to perform an action at a suitable time Intent Intent = new Intent (this,notificationactivity.class); Pendingintent pendingintent = pendingintent.getactivity (this,0,intent,0); LOG.D ("TAG", "dddddddddddddddddddd"); Notificationmanager manager = (Notificationmanager) getsystemservice (Notification_service); Why use Notificationcompat here is to adapt to the problem of API instability, each version will be more or less modify the notification content, using this will not have such a problem//Notificationcompat.builder (Co ntext context). Build () Get notification//Note the following two settings Setautocancel setcontentintent notificat ION notification = new Notificationcompat.builder (this). Setcontenttitle ("the is a notification "). Setcontenttext (" Simply give you a piece of content that lets you see what it is ") . Setautocancel (True) . Setsmallicon (R.mipmap.ic_launcher). Setlargeicon (Bitmap Factory.decoderesource (Getresources (), R.mipmap.ic_launcher)). Setcontentint ENT (pendingintent). build (); Note here the 1, here's 1 is to give this notice the specified ID//can be set here by the ID of this notification after clicking on the notification bar to set the notification disappears, as in the following way//here set the notification cancellation// Notificationmanager Notificationmanager = (notificationmanager) getsystemservice (Notification_service); Notificationmanager.cancel (1); Manager.notify (1,notification);
Note that the above code in the latter we set the response of the click Notification, that is, intent, you need to pay special attention to the point is that you can also be displayed in the specific display of the active page in the setting of the cancellation notification display, the code as shown in the second penultimate line.
Android Learning-Using notifications