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!