gpt4 book ai didi

java - 在自定义内容通知中使用后更新 RemoteView

转载 作者:行者123 更新时间:2023-12-01 18:06:24 26 4
gpt4 key购买 nike

我正在尝试使用自定义远程 View 创建媒体播放器控件通知。我遇到的问题是,每次我在远程 View 中更改某些内容时,我都需要取消通知并从头开始重建它。这种方法对性能非常不利,因为它明显滞后。 (即将暂停图标更改为仅播放图标,我需要重建整个通知并重新加载专辑图像)

我尝试更改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 是使用新内容创建或更新的通知对象。

这个site有一个如何用 Java 更新通知的示例。

关于java - 在自定义内容通知中使用后更新 RemoteView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60550289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com