Android Learning-Using notifications

Source: Internet
Author: User

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

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.