Android Note: Notifications

Source: Internet
Author: User

It can be created in an activity or in a broadcast receiver, and can be created in a service.

Notificationmanager manager = (Notificationmanager) getsystemservice (Context.notification_service);

Creating a Notification object can be written as:
Notification Notification = new Notification (R.drawable.icon, "—————— This is ticker text ——————", System.currenttimemillis ());

When the icon just came out, it flashed. Time Created

Notification.setlatesteventinfo (Context, "This is the content title", "This iscontent text", null);

Title Body

Manager.notify (1, notification);//The number represents the ID, and the ID of each message should be different.

Pendingintent provides several static methods for obtaining pendingintent instances, which can be selected using the Getactivity () method, the Getbroadcast () method, or the GetService () method, depending on the requirements.

The first parameter is a context. The second parameter is passed in 0. The third parameter is a intent object that can be used to construct the pendingintent "intent" of the object.

The fourth parameter is used to determine the behavior of the pendingintent, with the four values of Flag_one_shot, Flag_no_create, Flag_cancel_current, and flag_update_current optional.

Intent Intent = new Intent (this, notificationactivity.class);
pendingintent pi = pendingintent.getactivity (this, 0, intent,pendingintent.flag_cancel_current);
Notification.setlatesteventinfo (This, "This is the content title", "This is content text", pi);//The fourth parameter is called Pendingintent.

Notificationmanager manager = (Notificationmanager) getsystemservice (Notification_service);
Manager.cancel (1);//Canceling the notification "1" is the ID that was passed in at the beginning.

Android Note: 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.