Android NotificationListenerService 取消通知 [英] Android NotificationListenerService cancel notification

查看:144
本文介绍了Android NotificationListenerService 取消通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NotificationListenerService 和一个:

I have a NotificationListenerService and a:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Log.i(TAG,"**********  onNotificationPosted");
    Log.i(TAG,"ID :" + sbn.getId() + "t" + sbn.getNotification().tickerText + "t" + sbn.getPackageName());
}

如何从 onNotificationPosted() 取消该通知?我尝试了一个简单的 manager.cancel(sbn.getId()); 但它没有用

How can I cancel that notification from the onNotificationPosted()? I tried a simple manager.cancel(sbn.getId()); but it didn't worked

推荐答案

尝试 :
manager.cancel(sbn.getTag(), sbn.getId());

如果这不起作用,您可以尝试
manager.cancel(sbn.getTag(), sbn.getId(), sbn.getUser());

If this doesn't work, you can try
manager.cancel(sbn.getTag(), sbn.getId(), sbn.getUser());

您还可以使用以下方法取消所有通知:
manager.cancelAll();

You can also cancel all notifications by using :
manager.cancelAll();

这篇关于Android NotificationListenerService 取消通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆