3

I would like to keep the notification ON from the settings, and want to clear notification of Whatsapp after 2 min of receiving. I searched it online where I found out how to remove notification Click here. ClearAll and clear via notification ID was described, but I do not know how to find the ID.

  • Check this out: https://stackoverflow.com/questions/31615241/in-android-how-can-i-know-the-current-notification-id-to-clear-the-notification – Pierre Ghaly Jul 17 '18 at 18:40
  • I want to find notification id of WhatsApp not my app – Rahul Agrawal Jul 17 '18 at 19:28
  • Check out my answer here: https://stackoverflow.com/questions/51075189/i-want-to-hide-all-notifications-of-other-apps-when-my-android-app-is-in-foregro/51272687#51272687 Just instead of cancelling every notification you need to cancel whatsapp ones so in onNotificationPosted use if(sbm.getPackageName().equals("com.whatsapp")) cancelNotification(sbm.getKey()); instead of cancelAllNotifications as in previous answer – Bhavita Lalwani Jul 18 '18 at 12:23

1 Answers1

0

Why did you post screenshot of documentation?

And it's not as simple as you think - notification ID is package specific, which means NotificationManager.cancel(id) and NotificationManager.cancelAll() only affect notifications posted by your app.

If you want to cancel other applications notifications you need to write your own NotificationListenerService. Additionally user will need to manually grant notification access for your app in system settings.

Pawel
  • 15,548
  • 3
  • 36
  • 36
  • Yes, I've made NotificationListenerService class and instructed user to manually grant notification access to my app. Now if I want to dismiss Whatsapp notification, how can I do it?? Thanks in advance – Rahul Agrawal Jul 17 '18 at 19:00
  • @RahulAgrawal You need to use `NotificationListenerService.getActiveNotifications()` then filter through them to find the one coming from your desired package. – Pawel Jul 17 '18 at 19:49