单击操作后如何关闭通知 [英] How to dismiss notification after action has been clicked

查看:41
本文介绍了单击操作后如何关闭通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自 API 级别 16 (Jelly Bean) 起,可以使用

Since API level 16 (Jelly Bean), there is the possibility to add actions to a notification with

builder.addAction(iconId, title, intent);

但是当我向通知添加一个操作并按下该操作时,该通知不会被解除.当通知本身被点击时,它可以被关闭

But when I add an action to a notification and the action is pressed, the notification is not going to be dismissed. When the notification itself is being clicked, it can be dismissed with

notification.flags = Notification.FLAG_AUTO_CANCEL;

builder.setAutoCancel(true);

但显然,这与与通知相关的操作无关.

But obviously, this has nothing to with the actions associated to the notification.

有什么提示吗?或者这还不是 API 的一部分?我什么都没找到.

Any hints? Or is this not part of the API yet? I did not find anything.

推荐答案

当您在通知管理器上调用 notify 时,您给了它一个 id - 这是您以后可以用来访问它的唯一 id(这是来自通知管理器:

When you called notify on the notification manager you gave it an id - that is the unique id you can use to access it later (this is from the notification manager:

notify(int id, Notification notification)

要取消,您可以调用:

cancel(int id)

具有相同的 ID.所以,基本上,您需要跟踪 id 或可能将 id 放入一个 Bundle 中,然后添加到 PendingIntent 中的 Intent 中?

with the same id. So, basically, you need to keep track of the id or possibly put the id into a Bundle you add to the Intent inside the PendingIntent?

这篇关于单击操作后如何关闭通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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