单击动作后如何关闭通知 [英] How to dismiss notification after action has been clicked
问题描述
自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放入在PendingIntent内添加到Intent的Bundle中?
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屋!