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