Public classMainactivityextendsActivity {Button btnsend; Button Btncancel; Private Static Final intnotification_id = 0; PrivateNotificationmanager Notificationmanager; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.notification); Btnsend=(Button) Findviewbyid (r.id.btn_send); Btncancel=(Button) Findviewbyid (r.id.btn_cancel); Notificationmanager=(Notificationmanager) Getsystemservice (Notification_service); Btnsend.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//Create a intent that initiates other activityIntent Intent =NewIntent (mainactivity. This, Wndvideolist.class); Pendingintent pendingintent= Pendingintent.getactivity (mainactivity. This, 0, intent, 0); Notification Notification=NewNotification.builder (mainactivity. This). Setautocancel (true)//Open the notification and the notification disappears automatically. Setticker ("new Message")//set up a notification prompt that appears in the status bar. Setsmallicon (R.drawable.icon)//to set the icon for a notification. Setcontenttitle ("A new notice")//set the title of the notification content. Setcontenttext ("Congratulations on your special and handsome ... ")//set the contents of a notification. SetDefaults (Notification.default_all)//default use of system sound LED lights and so on. Setwhen (System.currenttimemillis ())//Set the time. Setcontentintent (Pendingintent)//Set Intent. Build (); Notificationmanager.notify (notification_id, NOTIFICATION); } }); Btncancel.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {notificationmanager.cancel (notification_id); } }); }}
Notification Notice Bar