Response events that detect three states of the Android notification bar primarily
This time in the implementation of push demand, to use the Android notification bar notification Click to enter the Message page, because to achieve a save push user name function, I clicked on after the function, but the test found that I click Delete or swipe to clear after this function is not executed, That's why you're aware of the events to handle delete and slide cleanup:
First implement a broadcastreceiver
Public classNotificationbroadcastreceiverextendsBroadcastreceiver { Public Static FinalString type = "type";//This type is for notification update information, this does not understand the friend can go to search, a lot of@Override Public voidOnReceive (Context context, Intent Intent) {String action=intent.getaction (); intType = Intent.getintextra (type,-1); if(Type! =-1) {Notificationmanager Notificationmanager=(Notificationmanager) Context.getsystemservice (Context.notification_service); Notificationmanager.cancel (type); } if(Action.equals ("notification_clicked")) { //Handling Click events } if(Action.equals ("notification_cancelled")) { //handling swipe cleanup and click Delete Events } }}
and the registration Notification is this:
Intent Intentclick =NewIntent ( This, Notificationbroadcastreceiver.class); Intentclick.setaction ("Notification_clicked"); Intentclick.putextra (Notificationbroadcastreceiver.type, TYPE); Pendingintent Pendingintentclick= Pendingintent.getbroadcast ( This, 0, Intentclick, pendingintent.flag_one_shot); Intent intentcancel=NewIntent ( This, Notificationbroadcastreceiver.class); Intentcancel.setaction ("Notification_cancelled"); Intentcancel.putextra (Notificationbroadcastreceiver.type, TYPE); Pendingintent Pendingintentcancel= Pendingintent.getbroadcast ( This, 0, Intentcancel, pendingintent.flag_one_shot); Uri Defaultsounduri=Ringtonemanager.getdefaulturi (ringtonemanager.type_notification); Notificationcompat.builder Notificationbuilder=NewNotificationcompat.builder ( This). Setsmallicon (R.drawable.ic_launcher). Setcontenttitle (GetString (R.string.setting_gcm_title)). Setcontenttext (Message). Setsound (Defaultsounduri). Setcontentintent (Pendingintentclick). Setdeletein Tent (pendingintentcancel); Notificationmanager=(Notificationmanager) Getsystemservice (Context.notification_service); Notificationmanager.notify (Type/*ID of notification*/, Notificationbuilder.build ());//This is the type, the same update, the different add
Of course, don't forget to register in Androidmanifest.xml .
<receiverAndroid:name= ". Gcm. Notificationbroadcastreceiver "> <Intent-filter> <ActionAndroid:name= "notification_cancelled"/> <ActionAndroid:name= "notification_clicked"/> </Intent-filter></receiver>
This is the initial implementation of the Android notification bar notification Click, Cancel, clear response events
Android Notification bar notification Click, Cancel, clear response event