通知。setContentText未在Android 10上显示
我有一个简单的可扩展通知 正常布局:通知。setContentText未在Android 10上显示,android,android-notifications,Android,Android Notifications,我有一个简单的可扩展通知 正常布局: 标题 ShortText(.setContentText) 解释: 标题 Long文本(.setStyle) 在Android 10(API 29)中,这不再起作用,因为只有长文本部分显示。看看右上角的小箭头 这是一个bug还是一个功能?谷歌已经确认这是一个bug:请显示您在每个平台上看到的屏幕截图 val builder = NotificationCompat.Builder(this, CHANNEL_TEST_ID) .setSmallIc
标题
ShortText(.setContentText)
解释:
标题
Long文本(.setStyle)
在Android 10(API 29)中,这不再起作用,因为只有长文本部分显示。看看右上角的小箭头
这是一个bug还是一个功能?谷歌已经确认这是一个bug:请显示您在每个平台上看到的屏幕截图
val builder = NotificationCompat.Builder(this, CHANNEL_TEST_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("This is the title")
.setContentText("This is the content, which is not displayed in Android 10.")
.setStyle(NotificationCompat.BigTextStyle().bigText("The only displayed text in Android 10. contentText missing."))
.setPriority(NotificationCompat.PRIORITY_HIGH) // by channel from Android 8
.setAutoCancel(true) // Android 8
with(NotificationManagerCompat.from(this)) {
// notificationId is a unique int for each notification that you must define
notify(101, builder.build())
}
private const val CHANNEL_TEST_ID = "TEST"
private fun createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = "Test"
val descriptionText = "Test"
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel(CHANNEL_TEST_ID, name, importance).apply {
description = descriptionText
}
// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}