Android - 从通知中删除操作按钮 [英] Android - Remove action button from notification

查看:101
本文介绍了Android - 从通知中删除操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击这些操作按钮时关闭通知操作按钮(而不是整个通知).(假设:带有停止操作按钮的下载通知.点击停止时,关闭停止按钮并将 contentText 更改为下载已取消")

I want to dismiss the notification action buttons (not the whole notification) when clicking on those action buttons. (Lets say: a download notification with stop action button. When click on stop, dismiss stop button and change contentText to 'Download canceled')

我唯一想到的是取消通知并通知另一个具有相同 ID 的人,但这似乎是一个丑陋的解决方法......

The only thing it comes to my mind is to cancel notification and notify another one with the same id, but this seems to be an ugly workaround...

那么,有没有办法从通知中删除操作按钮?

So, is there any way to remove action buttons from notifications?

(我认为没有必要放任何代码,但如果有必要我会...)

(i think there is no need to put any code, but I will if its necessary...)

推荐答案

如果您使用的是 v4 支持库中的 NotificationCompat.Builder,您可以直接访问构建器的操作集合(遗憾的是没有提供公共修改器).

If you are using the NotificationCompat.Builder from the v4 Support Library, you can simply access the builder's action collection directly (Unfortunately no public mutators are provided).

以下内容可以解决问题(当然您必须更新重新通知):

The following will do the trick (Of course you must update re-notify):

NotificationCompat.Builder notifBuilder = NotificationCompat.Builder(context);
...
notifBuilder.mActions.clear();

这篇关于Android - 从通知中删除操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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