Remove notification from notification bar from other applications

后端 未结 3 679
太阳男子
太阳男子 2020-12-09 09:37

I want to remove notifications from another application shown in the notification bar. Is that possible? NotificationManager.cancelAll(); cancels only notificat

相关标签:
3条回答
  • 2020-12-09 10:00

    You can close any notification use NotificationListenerService:

    public class NotificationListener extends NotificationListenerService {
    
        @Override
        public void onNotificationPosted(StatusBarNotification sbn) {
          cancelNotification(sbn.getKey());
        }
    }
    

    Your application must have BIND_NOTIFICATION_LISTENER_SERVICE permission. https://developer.android.com/reference/android/service/notification/NotificationListenerService.html

    0 讨论(0)
  • 2020-12-09 10:03

    You can cancel your own notifications using NotificationManager.
    But you can't cancel other apps' notifications, that is not possible.

    0 讨论(0)
  • 2020-12-09 10:11

    From Android 4.3 onward, you can now cancel notifications from any apps.

    You need to register your app as NotificationListenerService, then call NotificationListenerService.cancelNotification(String pkg, String tag, int id) to cancel one notification.

    0 讨论(0)
提交回复
热议问题