Notification is the message tip at the top of the Android phone
Here we set two buttons respectively, to achieve the top of the message send and cancel
function implementation
The first thing to do is to set up a notification control class in the main activity
Notificationmanager Manager; Notification Control class
Then get the system service in the OnCreate method
Manager = (notificationmanager) getsystemservice (Context.notification_service);
Then set the notification bar information
private void SendNotification () { Intent Intent = new Intent (this,mainactivity.class); Pendingintent pintent = pendingintent.getactivity (this,0,intent,0); Builder builder = new Builder (this); Builder.setsmallicon (R.mipmap.ic_launcher);//Set icon builder.setticker ("Hello");//Set phone status bar prompt Builder.setwhen (System.currenttimemillis ());//Time Builder.setcontenttitle ("Notification notification Bar");//title Builder.setcontenttext ("I am Little Hao");//notification content builder.setcontentintent (pintent);//Click after the intent builder.setdefaults ( Notification.default_all);//give notice to set the vibration, sound, and hint light three kinds of effects, but remember to apply for permission Notification Notification = Builder.build (); Above 4.1 versions Use this method //builder.getnotification (); Version 4.1 follows this method manager.notify (notification_id,notification); }
Add vibration and Cue light permissions to the Mainfest file
<uses-permission android:name= "Android.permission.VIBRATE" ></uses-permission> < Uses-permission android:name= "Android.permission.FLASHLIGHT" ></uses-permission>
ANDROID Info Notification Bar message notification