Android (Notificationmanager send notifications)

Source: Internet
Author: User

The interface of the application is as follows, the interface code is not given here

Mainactivity.java

1  Public classMainactivityextendsActivity {2     PrivateTextView Tvtitle;3     PrivateTextView tvcontent;4     PrivateButton btnsend;5     PrivateString title;6     PrivateString content;7     8      Public voidonCreate (Bundle savedinstancestate) {9         Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.activity_main); One          Atvtitle=(TextView) Findviewbyid (R.ID.EDITTEXT1); -Tvcontent=(TextView) Findviewbyid (r.id.edittext01); -Btnsend=(Button) Findviewbyid (r.id.btnsend); the  -Btnsend.setonclicklistener (NewOnclicklistener () { -  - @Override +              Public voidOnClick (View v) { -                 //TODO auto-generated Method Stub + send (); A             } at         }); -          -     } -      Public voidSend () { -Title=tvtitle.gettext (). toString ();//title -Content=tvcontent.gettext (). toString ();//content in          -         //1. Get Notificationmanager service toNotificationmanager nm=(Notificationmanager) Getsystemservice (context.notification_service); +         //2. Instantiate a notification that specifies the icon, profile, time -Notification n =NewNotification (R.drawable.ic_launcher, "notifications", System.currenttimemillis ()); the         //3. Specify the title, content, and intent of the notification *Intent Intent =NewIntent ( This, Mainactivity.class); $Pendingintent pi= pendingintent.getactivity ( This, 0, intent, 0);Panax NotoginsengN.setlatesteventinfo ( This, title, Content, pi); -         //Specify Sound the         //n.defaults = notification.default_sound; +         //4. Send Notifications ANm.notify (1, n); the     } +  -}

Click "Send" button, you can display the message sent in the 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.