Android 45 Notifications

Source: Internet
Author: User

 Packagecom.sxt.day07_01;Importandroid.app.Activity;Importandroid.app.Notification;ImportAndroid.app.NotificationManager;Importandroid.app.PendingIntent;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    Setlistener (); }    Private voidSetlistener () {Findviewbyid (r.id.btnsendnotification). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//Create a intent object that launches the target activity, and click on the notification to jump to the Secondactivity pageIntent intent=NewIntent (mainactivity. This, Secondactivity.class); //Create a Pendingintent objectPendingintent pi=pendingintent.getactivity (mainactivity. This, 0, intent, 0); //Create a Notification objectNotification notif=NewNotification (R.drawable.ic_launcher, "notice coming!", System.currenttimemillis ());//no drop-down notification of the picture, notification of the topic, notification of delivery time//set tap notifications for listeningNotif.setlatesteventinfo (mainactivity. This, "Your right 16 software can be updated", "Click to start Updating", pi);//after pulling down the drop-down bar, notify the displayed text. //Create a Notification Manager ObjectNotificationmanager manager= (Notificationmanager) Getsystemservice (Context.notification_service);//Getsystemservice access to system services//Send NotificationsManager.notify (Notif);//99 is the ID value of the notification//Manager.cancel (in);            }        }); }}

Android 45 Notifications

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.