"Android" monitor notification is cleared

Source: Internet
Author: User


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

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.