Package Com.example.mynotification;import Android.os.bundle;import Android.app.activity;import Android.app.notification;import Android.app.notificationmanager;import Android.app.pendingintent;import Android.content.intent;import Android.support.v4.app.notificationcompat;import Android.view.Menu;public Class Mainactivity extends Activity {public pendingintent getdefalutintent (int flags) {Pendingintent pendingintent= Pendingintent.getactivity (this, 1, new Intent (), flags); return pendingintent;} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Notificationmanager Mnotificationmanager = (notificationmanager) getsystemservice (Notification_service); Notificationcompat.builder Mbuilder = new Notificationcompat.builder (this); Mbuilder.setcontenttitle ("test title")//Set the notification bar header. Setcontenttext ("Test Content")//Set the notification bar to display content. Setcontentintent (Getdefalutintent ( Notification.flag_auto_cancel)//Set the notification bar click Intent//.setnumber (number);. SettIcker ("Test notifications Come")//notification bar first appears in the notification bar, with animated effects. Setwhen (System.currenttimemillis ())//notification bar time, generally directly using the system. SetPriority ( Notification.default_all)//Set the notification bar priority//.setautocancel (TRUE)//the user clicks the panel and disappears. Setongoing (false)//true, set him as an in-progress notification. They are usually used to represent a background task that the user actively participates in (such as playing music) or is waiting in some way, so//occupy the device (such as a file download, synchronous operation, active network connection). SetDefaults (notification.default_vibrate The simplest and most consistent way to add sound, strobe, and vibration effects to notifications is to use the current user defaults,//Use the default property to combine//notification.default_all notification.default_ Sound add voice//requires vibrate permission. Setsmallicon (R.drawable.ic_launcher); Notification Notification = Mbuilder.build (); notification.flags = notification.flag_ongoing_event; Notification.flags = notification.flag_no_clear;//Click to clear Intent intent = new Intent (Getapplicationcontext (), Mainactivity.class); intent.addcategory (Intent.category_launcher); Intent.setflags (intent.flag_activity_new_task| intent.flag_activity_reset_task_if_needed); Pendingintent pendingintent = pendingintent.getactivity (Getapplicationcontext (), 0, intent, 0); Mbuilder.setcontentintent(pendingintent); Mnotificationmanager.notify (0,mbuilder.build ()); } @Overridepublic Boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action Bar if it is P Resent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}I do not know why my click will still clear, depressed.
Implementation of the Android notification bar