Objective
Generally very resident notification can be cleared by the user, if you can listen to the cleared event can do something, such as push re-count problem.
StatementWelcome reprint, but please keep the original source of the article:)Blog Park: http://www.cnblogs.comFarmer Uncle: Http://over140.cnblogs.com
Body
PrivateFinalBroadcastreceiver Mbroadcastreceiver =NewBroadcastreceiver () {
@Override
PublicvoidOnReceive (context 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;
}Elseif(Push_type_live.equals (TYPE)) {
//mnumlives = 0;
}
//This can be re-counted .
}
};
PrivatevoidSendlivenotification () {
Intent Intent =NewIntent (notification_click_action);
Notificationcompat.builder Mbuilder =NewNotificationcompat.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,NewIntent (notification_deleted_action). PutExtra (Push_type, push_type_live), 0);
Mnotificationmanager.notify (Notification_id_live, Mbuilder.build ());
}
Code description
1, the most important is the setdeleteintent, this in the API level (Android 3.0) New
2. Be careful not to set Setautocancel to true, otherwise the listener will not receive
3, here Unified the click Notification and the action to eliminate notifications
4, pay attention to the broadcast before the push to register good
End
Long time no blog, no excuses.
"Android" monitor notification is cleared