Notice
Directly on the example, the first simple point, just a hint message, click to call a page
The second one displays a download prompt with progress
Example 1
Activity_main.xml
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Horizontal" > <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Send Notification" /> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Turn off notifications" /></LinearLayout>
View Code
Mainactivity.java
Public classMainactivityextendsActivity {notificationmanager nm; Button btn1; Button btn2; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //get the Notificationmanager service for your systemnm=(Notificationmanager) Getsystemservice (Notification_service); BTN1=(Button) Findviewbyid (R.id.button1); BTN2=(Button) Findviewbyid (R.id.button2); Btn1.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {Intent Intent=NewIntent (mainactivity. This, Loginactivity.class); //Packaging of IntentPendingintent pi=pendingintent.getactivity (mainactivity. This, 0, intent, 0); //Create a notificationNotification nf=NewNotification.builder (mainactivity. This) //whether to close automatically. Setautocancel (true) //Alert information for notifications. Setticker ("New News") //Small Icons. Setsmallicon (R.drawable.ic_launcher)//Notification title. Setcontenttitle ("A new notice") //Notification Content. Setcontenttext ("There are new notifications, click to view") //Set system default sound, default LED light//. SetDefaults (notification.default_sound| Notification.default_lights)//set a custom sound//. Setsound (sound)//when will it start?. Setwhen (System.currenttimemillis ())//Set the intent for this notification to start. Setcontentintent (PI). build (); //SendNm.notify (1234, NF); } }); Btn2.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//CancelNm.cancel (1234); } }); }}
View Code
Example 2
Android Learning-Interface-ui-notification