android - Cant cancel Notification using NotificationListenerService -


this service:

public class listener extends notificationlistenerservice {        context context;      @override      public void oncreate() {          super.oncreate();         context = getapplicationcontext();      }      @override      public void onnotificationposted(statusbarnotification sbn) {           string pack = sbn.getpackagename();         string ticker = sbn.getnotification().tickertext.tostring();         bundle extras = sbn.getnotification().extras;         string title = extras.getstring("android.title");         string text = extras.getcharsequence("android.text").tostring();          log.i("msg",pack);         log.i("msg",ticker);         log.i("msg",title);         log.i("msg",text);          intent msgrcv = new intent("msg");         msgrcv.putextra("package", pack);         msgrcv.putextra("ticker", ticker);         msgrcv.putextra("title", title);         msgrcv.putextra("text", text);          localbroadcastmanager.getinstance(context).sendbroadcast(msgrcv);         toast.maketext(context, "got something", toast.length_long).show();   //final string t=  sbn.getkey();          listener.this.cancelallnotifications();     }      @override      public void onnotificationremoved(statusbarnotification sbn) {         log.i("msg","notification removed");      }   } 

for testing, dismiss notifications app arrive. have called listener.this.cancelallnotifications(); inside onnotificationposted, not work.

what doing wrong ? testing on android version 5.0.2.

p.s.

i have added permissions along intent filter, android mentions.

<service android:name=".notificationlistener"           android:label="@string/service_name"           android:permission="android.permission.bind_notification_listener_service">      <intent-filter>          <action android:name="android.service.notification.notificationlistenerservice" />      </intent-filter>  </service> 

make sure 'notification access' active (checked) app implementing notificationlistenerservice.

it can verified in 'settings' menu. @ either of addresses depending upon android version. android 5.0, should at: settings -> sound & notification -> notification access

or else, may find at: settings -> security -> notification access

try enabling app , try clear notifications.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -