Android study notes 35: Notification

Source: Internet
Author: User

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"/>
Related Article

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.