Notification Notification of Android development

Source: Internet
Author: User

Message notification makes us very common, when a message is received, the notification bar will display a notification;

Look directly at the code:

1  Public classMainactivityextendsActivity {2 3     Privatenotificationmanager nm;4 @Override5     protected voidonCreate (Bundle savedinstancestate) {6         Super. OnCreate (savedinstancestate);7 Setcontentview (r.layout.activity_main);8NM =(Notificationmanager) Getsystemservice (notification_service);9     }Ten  One      Public voidClick (View v) { ANotification Notification =NewNotification.builder ( This) -. Setcontenttitle ("I am the headline") -. Setcontenttext ("I am the content of the title") the . Setsmallicon (R.mipmap.ic_launcher) - . Setlargeicon (Bitmapfactory.decoderesource (Getresources (), r.mipmap.ic_launcher)) - . Build (); -Nm.notify (10, notification); +     } -      Public voidClick1 (View v) { +Nm.cancel (10); A     } at}

You first create an instance of notification, and then send the notification out through an instance of Notificationmanager.

Nm.notify (Ten, notification);

Issue a notification with ID 10;

Nm.cancel (ten);
Cancels the notification with ID 10.

Notification Notification of Android development

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.