Android notification bar implementation
Package com. example. mynotification; import android. OS. bundle; import android. app. activity; import android. app. notification; import android. app. icationicationmanager; 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) {PendingInten T pendingIntent = PendingIntent. getActivity (this, 1, new Intent (), flags); return pendingIntent ;}@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); icationicationmanager mNotificationManager = (icationicationmanager) getSystemService (icationication_service); NotificationCompat. builder mBuilder = new NotificationCompat. bui Lder (this); mBuilder. setContentTitle ("test title") // set the title of the notification bar. setContentText ("Test content") // set the display content in the notification bar. setContentIntent (getDefalutIntent (Notification. FLAG_AUTO_CANCEL) // set the intent of clicking in the notification bar //. setNumber (number );. setTicker ("") // The notification bar appears in the notification bar for the first time, with animation effect. setWhen (System. currentTimeMillis () // The notification bar time. Generally, the system is used directly. setPriority (Notification. DEFAULT_ALL) // set the priority of the notification bar //. setAutoCancel (true) // The user disappears after clicking the panel. setOngoing (false) // true, set it to an ongoing notification. They are usually used to represent a background task. users actively participate (such as playing music) or are waiting in some way, so they // occupy devices (such as downloading a file and performing synchronization operations, active Network connection ). setDefaults (Notification. DEFAULT_VIBRATE) // The simplest and most consistent way to add sound, flashing, and vibration effects to the notification is to use the default settings of the current user, // use the default attribute, can be combined // Notification. DEFAULT_ALL Notification. DEFAULT_SOUND: Add a sound // requires VIBRATE permission. setSmallIcon (R. drawable. ic_launcher); Notification notification = mBuilder. build (); notification. flags = Notification. FLAG_ONGOING_EVENT; notification. flags = Notification. FLAG_NO_CLEAR; // when you click clear, Intent intent = new Intent (getApplicationContext (), MainActivity is not cleared. 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); micationicationmanager. notify (0, mBuilder. build () ;}@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}
I don't know why my clicks will still be cleared.