Android "Local notification Notification"

Source: Internet
Author: User

public class Notificationtest extends activity{static final int notification_id = 0x1123; @Overridepublic void OnCreate (Bu Ndle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main);// Gets the button object in the App interface button bn = (Button) Findviewbyid (r.id.bn);//Event listener Bn.setonclicklistener for the buttons ' click event (new View.onclicklistener () {@Overridepublic void OnClick (View source) {//Creates a intentintent intent = new intent that initiates other activity ( Notificationtest.this, Otheractivity.class); pendingintent pi = pendingintent.getactivity (notificationtest.this, 0, intent, 0);//Create a Notificationnotification notify = new Notification ();//Set the icon for Notification, which is displayed in the status bar Notify.icon = r.drawable.notify;//Sets the text content for Notification, The text is displayed in the status bar Notify.tickertext = "Start other activity notifications";//Set send time for notification Notify.when = System.currenttimemillis ();// Set the sound for Notification notify.defaults = notification.default_sound;//Set default sound for Notification, default vibration, default Flash notify.defaults = notification.default_all;//Setting Event information Notify.setlatesteventinfo (notificationtest. This, "General notice", "Click to view", pi);//Get the system's Notificationmanager service Notificationmanager Notificationmanager = ( Notificationmanager) Getsystemservice (notification_service);//Send notification notificationmanager.notify (NOTIFICATION_ID, notify);}); /Cancel notification Button del = (Button) Findviewbyid (R.id.del);d El.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//Get System Notificationmanager Service Notificationmanager Notificationmanager = (Notificationmanager) Getsystemservice (Notification_service);//cancellation Notice notificationmanager.cancel (notification_id);}});}}

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.