java - 在自定义内容通知中使用后更新 remoteView
问题描述
我正在尝试使用自定义 remoteView 创建媒体播放器控件通知。我遇到的问题是,每次我在远程视图中更改某些内容时,我都需要取消通知并从头开始重建它。这种方法对性能非常不利,因为它明显滞后。(即将暂停图标更改为仅播放图标,我需要重建整个通知并重新加载专辑图像)
我尝试更改 remoteView,然后使用重新设置它NotificationBuilder.setCustomContentView
但它不起作用,这是更改播放和暂停图标的代码:
public void PlayPause(){
this.play=!this.play;
if (this.play) {
Bitmap toggleBmp = BitmapFactory.decodeResource(parent.getResources(), R.drawable.baseline_pause_black_48);
remoteView.setImageViewBitmap(R.id.toggle, changeBitmapColor(toggleBmp,Color.parseColor(iconColor)));
} else {
Bitmap toggleBmp = BitmapFactory.decodeResource(parent.getResources(), R.drawable.baseline_play_arrow_black_48);
remoteView.setImageViewBitmap(R.id.toggle, changeBitmapColor(toggleBmp,Color.parseColor(iconColor)));
}
nBuilder.setCustomContentView(remoteView);
}
上面的代码不起作用,图标也不会改变。
解决方案
您应该能够使用新信息更新通知,而无需取消原始通知。
如果您使用唯一 ID 创建通知,则可以使用该 ID 通过使用NotificationManager.notify(id, notification)
.
id
您要更新的通知的唯一 ID在哪里,并且notification
是使用新内容创建或更新的通知对象。
这个站点有一个如何在 Java 中更新通知的示例。
推荐阅读
- mysql - 性能报告中的“运行时最高 5% 的语句”与慢查询日志有什么不同?
- python - 有没有办法让函数从同一个变量中获得两次随机数
- python - Tweepy:当我有它的 id 时,我如何从推文中获取信息
- sql - 语法不正确,在 SQL 中应为 '('
- python - 声明列表时的Python扩展列表
- python - 使用 NumPy 求和,其中 j != i
- ionic-framework - 无法添加cordova-plugin-telerik-imagepicker。
此插件的更改与 config.xml 中的更改 - r - 闪亮的renderText对reactiveValues的变化没有反应
- python - 我可以使用 Beautiful Soup 从 Web 上获取使用 HTML 显示的 XML 文件吗?
- javascript - 无法从 /projectFolder 中找到模块“react-native-reanimated/plugin”