Objective
Generally very resident notification can be cleared by the user, if can listen to the cleared event can do some things, such as the problem of pushing back counting.
Body
Private final Broadcastreceiver mbroadcastreceiver = new Broadcastreceiver () {@Override public void onreceive (Cont
Ext context, Intent Intent) {if (Intent = NULL | | context = = NULL) {return;
} mnotificationmanager.cancel (notification_id_live);
String type = Intent.getstringextra (Push_type);
if (Push_type_link.equals (TYPE)) {//mnumlinkes = 0;
else if (push_type_live.equals (TYPE)) {//mnumlives = 0;
}//Here can be counted again}};
private void Sendlivenotification () {Intent Intent = new Intent (notification_click_action);
Notificationcompat.builder Mbuilder = new Notificationcompat.builder (this);
String title = "Push Test";
Mbuilder.setcontenttitle (title);
Mbuilder.setticker (title);
Mbuilder.setcontenttext ("https://233.tv/over140");
Mbuilder.setlargeicon (Bitmapfactory.decoderesource (Getresources (), r.mipmap.ic_launcher));
Mbuilder.setsmallicon (R.drawable.ic_action_cast);
Mbuilder.setdefaults (Notification.default_all); Mbuilder. Setwhen (System.currenttimemillis ());
Mbuilder.setcontentintent (Pendingintent.getbroadcast (this, notification_id_live, intent, 0)); Mbuilder.setdeleteintent (Pendingintent.getbroadcast (This, notification_id_live, new Intent (notification_deleted_
ACTION). Putextra (Push_type, push_type_live), 0);
Mnotificationmanager.notify (Notification_id_live, Mbuilder.build ()); }
Code description
1, the most important thing is setdeleteintent, which is added to the API level (Android 3.0)
2. Note Do not set Setautocancel to true, otherwise the listener will not receive
3, here Unified click to notify and eliminate the operation of the notification
4, pay attention to the broadcast before the push to register good
The actual use found that there is still a problem, such as the service was killed, notice bar Click will not respond, this piece still need to consider, such as the broadcast in the Androidmainfest listening.
The above is a data collation of the Android Notification event, hoping to help friends with Android development.