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