Android--Use of notification bar

Source: Internet
Author: User

1.

2. Implementing the Code

  

 Public classFirstactivityextendsActivity {PrivateNotification Notification;//Notification Object    PrivateNotificationmanager Notificationmanager;//Notificationmanager Object@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                        Setcontentview (R.layout.main); Button BTN1= (Button) Findviewbyid (R.id.button1);//Get Button ObjectButton btn2 = (button) Findviewbyid (R.id.button2);//Get Button ObjectString Service= Notification_service;//Get System ServicesNotificationmanager =(Notificationmanager) getsystemservice (service); Notification=NewNotification ();//Instantiate a notificationNotification.icon = R.drawable.icon;//Specify iconNotification.tickertext = "Notification Test";//Specifying prompt informationNotification.when = System.currenttimemillis ();//Specify the time to displayBtn1.setonclicklistener (NewView.onclicklistener () {//Setting up Listeners@Override Public voidOnClick (View v) {//TODO auto-generated Method StubIntent Intent =NewIntent (firstactivity. This, firstactivity.class); //pendingintent equivalent to Intent's packaging class--and that's what's coming.Pendingintent pendingintent =pendingintent.getactivity (firstactivity. This, 0, intent, 0); Notification.setlatesteventinfo (firstactivity. This, "My title",                        "My Content", pendingintent); Notificationmanager.notify (1, notification);//Send a notification            }        }); Btn2.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubNotificationmanager.cancel (1);//Cancel Notification            }        }); }}
firstactivity

Android--Use of 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.