Android Notification notifications

Source: Internet
Author: User

1  Public classNotificationtestextendsActivity2 {3     Static Final intnotification_id = 0x123;4 notificationmanager nm;5 6 @Override7      Public voidonCreate (Bundle savedinstancestate)8     {9         Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.main); One         //get the Notificationmanager service for your system ANM =(Notificationmanager) - Getsystemservice (notification_service); -     } the  -     //defines an event-handling method for the Click event of a button that sends notifications -      Public voidSend (View source) -     { +         //Create a intent that initiates other activity -Intent Intent =NewIntent (notificationtest. This +, Otheractivity.class); APendingintent pi =pendingintent.getactivity ( atNotificationtest. This, 0, intent, 0); -Notification notify =NewNotification.builder ( This) -             //set to turn on the notification, the notification disappears automatically -. Setautocancel (true) -             //set up a notification prompt that appears in the status bar -. Setticker ("New News") in             //to set the icon for a notification - . Setsmallicon (r.drawable.notify) to             //set the title of the notification content +. Setcontenttitle ("A new notice") -             //Set notification content the. Setcontenttext ("Congratulations, you've got a raise, you're paying 20% more!")) *             // //set Use system default sound, default LED light $             //. SetDefaults (Notification.default_soundPanax Notoginseng             // | Notification.default_lights) -             //set a custom sound for notifications the. Setsound (Uri.parse ("android.resource://org.crazyit.ui/" ++r.raw.msg)) A . Setwhen (System.currenttimemillis ()) the             //change notification to start the program intent + . Setcontentintent (PI). build (); -         //Send Notifications $ Nm.notify (notification_id, notify); $     } -  -     //defines the event handling method for the Click event of the button that deletes the notification the      Public voiddel (View v) -     {Wuyi         //Cancel Notification the Nm.cancel (notification_id); -     } Wu}

Android Notification notifications

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.