-3

I want to delete a notification which is located on my status bar. I used Notification Manager.cancel() but it didn't work. I used cancelAll() too with the same result.

My code is:

public class NotificationListenerService extends android.service.notification.NotificationListenerService {

...

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.cancel(sbn.getId());
nManager.cancel(sbn.getTag(), sbn.getID());
nManager.cancelAll(); 
}

I found more answers here on SO but none solved my issue. The sbn object is right, I print in my log all its data.

It's possible to delete an exiting notification located on the status bar with Android API < 20? (so without using cancelNotification())

atapi19
  • 227
  • 1
  • 3
  • 14
  • why people downvoted my question without explain nothing? Is it a dumb question? Ok, but explain why it is. It's the only way to learn. – atapi19 Sep 17 '16 at 10:04

1 Answers1

0
asdcvf
  • 199
  • 3
  • 13
  • can you attach the code when you show notification item? – asdcvf Sep 17 '16 at 10:30
  • Log.i("Tag", sbn.getTag()); Log.i("ID", "" + sbn.getId()); result is: I/Tag: ONE_TO_ONE:100000283080218:100007345449145 I/ID: 10000 – atapi19 Sep 17 '16 at 10:39
  • you can try the method [link](https://developer.android.com/reference/android/service/notification/NotificationListenerService.html#cancelNotification(java.lang.String)) `cancelNotification` – asdcvf Sep 17 '16 at 10:45
  • cancelNotification is working but it can be used only with min API 21. No clue for cancel()? – atapi19 Sep 17 '16 at 10:54
  • with API < 21, you can try with function cancelNotification (String pkg, String tag, int id) – asdcvf Sep 17 '16 at 10:57
  • this is link : https://developer.android.com/reference/android/service/notification/NotificationListenerService.html#cancelNotification(java.lang.String,java.lang.String,int) – asdcvf Sep 17 '16 at 10:59
  • of course, but it running on API < 21.make sure the input data is correct. – asdcvf Sep 17 '16 at 11:22
  • the data is what I wrote up, It should be correct but I don't know why it is not working. – atapi19 Sep 17 '16 at 11:44