Notification should be a unique feature of Android phones. At least I have used mobile phones as if other systems do not have this feature. You can simply use notification to display a notification, or use notification to do other things, such as opening another activity.
This picture is a bit ugly. I think some pictures on some blogs are very smooth, and there are even mouse clicks. I don't know how they are made, hope you can give me some advice. Thank you!
To open another activity by using notification, you only need to specify a pendingintent for the setlatesteventinfo method.
Public class notificationtest extends activity {static final int notification_id = 0x1123; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // obtain the button object button bn = (button) findviewbyid (R. id. BN); // bind event listener bn to the Click Event of the button. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (View Source) {// create an in Tentintent intent = new intent (icationicationtest. this, otheractivity. class); pendingintent Pi = pendingintent. getactivity (icationicationtest. this, 0, intent, 0); // create a notificationnotification between Y = new notification (); // set the notification icon, which is displayed in the status bar between Y. icon = R. drawable. y; // set text content for notification. The text will be displayed in notify in the status bar. tickertext = "notifications for starting Other Activities"; // set the sending time to notify y. when = system. currenttim Emillis (); // set the sound y for notification. defaults = notification. default_sound; // set the default sound, default vibration, and default flashlight for notification. defaults = notification. default_all; // sets event information y. setlatesteventinfo (icationicationtest. this, "Yanzi is coming ~ "," Click to view ", Pi); // obtain the icationmanager service notifmanager manager = (icationicationmanager) getsystemservice (icationication_service); // send a notification to icationicationmanager. Y (ication_id _id, notify) ;}}); button del = (button) findviewbyid (R. id. del); Del. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {// obtain the system's icationicationmanager service icationicationmanager = (icationicationmanager) getsystemservice (icationication_service); // cancel notification icationicationmanager. cancel (icationication_id );}});}}
This notification uses the system flash and vibrator, so do not forget to Configure permissions for the program.
<! -- Add the permission to operate the flashlight --> <uses-Permission Android: Name = "android. Permission. Flashlight"/> <! -- Add the vibrator operation permission --> <uses-Permission Android: Name = "android. Permission. Vibrate"/>