Notice of all kinds (iii)--the outside

Source: Internet
Author: User

The previous introduction about notification has been able to complete most of the functions, this article mainly record, see but temporarily not useless on the knowledge points and functions.

One, the difference between a app,notification is a pair of ID or ID and tag, as the only notification identity.

* Each of the Notify methods takes anintID parameter and optionally a* {@link String} tag parameter, which may {@codeNULL}. These parameters* is used to form a pair (tag, id), or ({@codeNULL}, ID)ifTag is* Unspecified. This pair identifies Thisnotification from your apps to the*system, so-that pair should is unique within your app. If you call one*Of the Notify methods with a (tag, id) pair, which is currently active and* ANewset of notification parameters, it'll be updated. For example,*ifYou pass aNewstatus bar icon, the old icon in the status bar would* Being replaced with theNewOne . This was also the same tag and ID you pass* to the {@link #cancel (int)} or {@link #cancel (String,int)} method to clear* ThisNotification.

From this, we can see that for new or updated notifications, Android is not a method to differentiate, but to use the notification ID to differentiate

Second, for new and updated notification

In the notification class, there is an inner class builder, which can construct a notification for us.

eg

    Notificationmanager Notificationmanager;    Notification.builder Notificationbuilder;    Notification Notification;     = (Notificationmanager) Getsystemservice (context.notification_service);     New Notification.builder (this);    Notificationbuilder.setvibrate (newlong[]{100,200,100,200});    Notificationbuilder.setcontenttitle ("hi~");     = Notificationbuilder.build ();

As the code above is the use of Notification.builder to create a Notification, and set its vibration and title; With this Notification, it is easy to:

Notificationmanager.notify (111, notification);

111 of them are my random knock ID.

There are many properties that can be set in Notificationbuilder, not listed here (which may be added later in the appendix).

It says new.

If I want to modify the properties of the notification, then re-send it again. Some blogs on the Internet Write the method

Notification.setlatesteventinfo (context context, charsequence Contenttitle, Charsequence ContentText, PendingIntent Contentintent);

I can still find this method in notification's code, but this method has been deprecated.

 

* If Thisis an activity, it must include the*{@link Android.content.intent#flag_activity_new_task} FLAG, which requires*That's the care for task management as described in the* <a href= "{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html" >Tasks and back* stack</a>document. *     *@deprecated Use {@link Builder} instead. *@removed*/@Deprecated Public voidSetlatesteventinfo (Context context, charsequence Contenttitle, charsequence contenttext, pendingintent con tentintent) {Notification.builder Builder=NewNotification.builder (context);

In the new version, modifying notification still uses the builder class. Build a new notification, as long as the ID and tag, notify () out of just update the current.

For the time being, learn to add ...

Notice of all kinds (iii)--the outside

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.