Jes*_*ess 15 notifications android android-notifications
我有一个通知,我试图通过重复使用相同的Notification Builder来更新,但是没有办法清除按钮,你只能打电话addAction.不使用相同的Builder会导致通知闪烁,这是不可取的.这有什么解决方案吗?我正在使用NotificationCompatv4支持库.
notificationBuilder.mActions.clear();
Run Code Online (Sandbox Code Playgroud)
实际上是public ArrayList<Action>,因此您可以使用它来做任何想要的事情。
您有两种选择来实现这一目标:
remoteView.setViewVisibility(...)...或者更改按钮的文本...使用反射来清除构建器操作。会像下面这样工作:
try {
//Use reflection to remove all old actions
Field f = mNotificationBuilder.getClass().getDeclaredField("mActions");
f.setAccessible(true);
f.set(mNotificationBuilder, new ArrayList<>());
}
catch (NoSuchFieldException e) {}
catch (IllegalAccessException e) {}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
2425 次 |
| 最近记录: |