ANDROID Listener Notification cleared instance code _android

Source: Internet
Author: User

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.

Related Article

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.