如何清除Android 7.1中通知栏的所有通知?

时间:2018-08-09 23:17:53

标签: java android android-notifications android-7.1-nougat

我想清除通知栏的所有通知,并制作了一个单独的类,扩展了NotificationListenerService

motor2off

我的清单文件是这样的:

MS.motor1off()

那我想知道为什么每次通知到达时都不会删除?

还是有人知道某种无需使用package com.testando.teste; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; public class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { cancelNotification(sbn.getKey()); } } 类即可删除这些通知的方法,类似于“全部清除”按钮?

1 个答案:

答案 0 :(得分:0)

// Clears notification tray messages
    public static void clearNotifications(Context context) {
        try{
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancelAll();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

AndroidHive提供了有关

通知的详细教程

Firebase云消息传递

This tutorial是您的参考。希望对您有帮助。