问题描述
我发现 MediaStyle setStyle 在我使用时不起作用NotificationCompat.builder(this)
发出通知.
I've found out that the MediaStyle setStyle is not working when I'm using NotificationCompat.builder(this)
to make a notification.
我的意思是,当在 NotificationCompat.Builder(this)
上使用它时:
I mean, When using this on NotificationCompat.Builder(this)
:
.setStyle(new Notification.MediaStyle()
.setMediaSession(mySession))
它说它想要获得 NotificationCompat.style
而不是 Notification.MediaStyle
.
It saying it wants to get NotificationCompat.style
instead of Notification.MediaStyle
.
你能帮我解决这个问题吗?NotificationCompat 有什么替代品吗?
Can you help me solve that problem?Is there any replacement for the NotificationCompat?
谢谢.
推荐答案
2020年AndroidX可以使用如下代码-
For AndroidX in 2020 you can use following code -
builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle());
不要忘记在构建中添加 androidx.media 依赖项.gradle(模块:应用程序)
don't forget to add the androidx.media dependency in build.gradle(Module:app)
implementation "androidx.media:media:1.2.0"
这篇关于NotificationCompat.setStyle() 无法获取 Notification.MediaStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!