Android Learning-notification Message Notification

Source: Internet
Author: User

Recently in the project you need to use the message notification, the package itself into a method, when necessary to facilitate the call,

The following is a brief introduction to some constants, fields, and methods in the notification class: Constants:default_all    use all default values, such as sound, vibration, splash screen, etc. default_lights Use default flash hint Default_sounds use default prompt sound default_vibrate Use default phone shake   "description": Add phone Shake, be sure to add permissions in Manifest.xml:< Uses-permission android:name= "Android.permission.VIBRATE"/> Above the effect constants can be superimposed, that is, by Notification.defaults =default_ sound| Default_vibrate;  notification.defaults |= Default_sound (preferably tested on a real machine, not on a vibration effect simulator)                   //Setting the FLAG bit FLAG_AUTO_CANCEL  The notification can be cleared by the status bar Clear button flag_no_clear     The notification can be cleared by the status bar flag_ongoing_event notification placed in the running Flag_ Insistent whether or not the music has been played, for instance, to know the user responds to characters commonly used segment:contentintent  set Pendingintent object, click on Send this intentdefaults add default effect Flags Set flag bits, such as flag_no_clear icon settings icons Sound sets the tickertext of the text that appears in the status bar when the timestamp for this notification is sent/*********************************** Split Line ************************************************/Paste the source code:
 private void shownotification (charsequence title,charsequence text) {  // Get Notification Manager         NotificationManager manager =  ( Notificationmanager) Getsystemservice (context.notification_service);         //Build a Notification object (there are three parameters to pass, namely, icon, title and   time)         notification  notification = new notification (R.drawable.logo_notify,title,system.currenttimemillis ());         notification.flags = notification.flag_auto_cancel;/ /Click to disappear automatically         notification.defaults = notification.default _sound;//Sound Default         //content information to be displayed when you define a drop-down notification bar           context context = getapplicationcontext ();          //activity        intent intent = new  to jump after clicking on the notification Intent (This,target.class);         budgetsetting.budgetflag= "Setting";         PendingIntent pendingIntent =  Pendingintent.getactivity (accountadding.this,0,intent,0);                                                                              notification.setlatesteventinfo ( Getapplicationcontext (),  "notification title",  "notifications displayed",  pendingintent);         notification.setlatesteventinfo (Context, title, text, pendingintent);         // Notifies the user to generate a title bar message notification with Mnotificationmanager notify method           Manager.notify (1, notification);         finish ();      }

This article is from the "Qytag (upspringing)" blog, so be sure to keep this source http://qytag.blog.51cto.com/6125308/1590726

Android Learning-notification Message Notification

Related Article

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.