Implementation of the Android notification bar

Source: Internet
Author: User

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

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.