Android Learning-Interface-ui-notification

Source: Internet
Author: User

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

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.