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