在Android 12中,Mediastyle通知的颜色被转移至NotificationChannel。因此,为解决通知颜色丢失的问题,需将通知渠道的颜色设置为Mediastyle通知的颜色属性。以下是一个示例代码:
val channelId = "my_channel_01" val name = "My channel" val importance = NotificationManager.IMPORTANCE_HIGH var notificationColor = R.color.mediasyle_notification val channel = NotificationChannel(channelId, name, importance) channel.apply { description = "My channel description" lockscreenVisibility = Notification.VISIBILITY_PUBLIC enableLights(true) lightColor = notificationColor enableVibration(true) setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), null) } notificationManager.createNotificationChannel(channel)
请注意,您需要根据自己的应用程序和通知颜色属性进行适当修改。