Notification Notice Bar

Source: Internet
Author: User

 Public classMainactivityextendsActivity {Button btnsend;    Button Btncancel; Private Static Final intnotification_id = 0; PrivateNotificationmanager Notificationmanager; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Requestwindowfeature (Window.feature_no_title);        Setcontentview (r.layout.notification); Btnsend=(Button) Findviewbyid (r.id.btn_send); Btncancel=(Button) Findviewbyid (r.id.btn_cancel); Notificationmanager=(Notificationmanager) Getsystemservice (Notification_service); Btnsend.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//Create a intent that initiates other activityIntent Intent =NewIntent (mainactivity. This, Wndvideolist.class); Pendingintent pendingintent= Pendingintent.getactivity (mainactivity. This, 0, intent, 0); Notification Notification=NewNotification.builder (mainactivity. This). Setautocancel (true)//Open the notification and the notification disappears automatically. Setticker ("new Message")//set up a notification prompt that appears in the status bar. Setsmallicon (R.drawable.icon)//to set the icon for a notification. Setcontenttitle ("A new notice")//set the title of the notification content. Setcontenttext ("Congratulations on your special and handsome ... ")//set the contents of a notification. SetDefaults (Notification.default_all)//default use of system sound LED lights and so on. Setwhen (System.currenttimemillis ())//Set the time. Setcontentintent (Pendingintent)//Set Intent. Build ();            Notificationmanager.notify (notification_id, NOTIFICATION);        }        }); Btncancel.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {notificationmanager.cancel (notification_id);    }        }); }}

Notification Notice 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.