【发布时间】:2021-04-15 10:54:34
【问题描述】:
我开始收到来自运行 Android 11 的 MIUI 11 设备的奇怪崩溃(目前只有 Mi 10 和 Mi 10 lite 5G)。我认为这是一个平台问题,在我的应用中没有任何内容,因为它是针对小米 Android 11 的。
Fatal Exception: android.app.RemoteServiceException
Bad notification(tag=null, id=3249) posted from package de.crysxd.octoapp, crashing app(uid=10334, pid=23788): Couldn't inflate contentViewsjava.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification$MessagingStyle android.app.Notification$MessagingStyle.setConversationType(int)' on a null object reference
我知道类似的崩溃可能会发生,例如:在旧设备上使用 SVG 图标,但我已经使用 PNG。设备显示的通知只有两种,一种是前台服务,一种来自 Firebase。从崩溃的时间来看,似乎不太可能是 Firebase 通知。
这是我用来创建通知 (here in full) 的代码:
private fun createProgressNotification(progress: Int, title: String, status: String) = createNotificationBuilder()
.setContentTitle(title)
.setContentText(status)
.setProgress(maxProgress, progress, false)
.setOngoing(true)
.addCloseAction()
.setNotificationSilent()
.build()
private fun createCompletedNotification(name: String?) = createNotificationBuilder()
.setContentTitle(getString(R.string.notification_print_done_title))
.apply {
name?.let {
setContentText(it)
}
}
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.build()
private fun createDisconnectedNotification() = createNotificationBuilder()
.setContentTitle(getString(R.string.notification_printing_lost_connection_message))
.setContentText(lastEta)
.setProgress(maxProgress, 0, true)
.addCloseAction()
.setOngoing(false)
.setNotificationSilent()
.build()
private fun createInitialNotification() = createNotificationBuilder()
.setContentTitle(getString(R.string.notification_printing_title))
.setProgress(maxProgress, 0, true)
.setOngoing(true)
.addCloseAction()
.setNotificationSilent()
.build()
private fun createNotificationBuilder() = NotificationCompat.Builder(this, notificationChannelId)
.setColorized(true)
.setColor(ContextCompat.getColor(this, R.color.primary_light))
.setSmallIcon(R.drawable.ic_notification_default)
.setContentIntent(createStartAppPendingIntent())
任何人有同样的问题或知道解决方案?
【问题讨论】:
-
我在同一个设备上遇到同样的问题,但我不知道这是从哪里来的,你能重现它吗?
-
不,我没有任何进展。我知道这与小米的 Android 11 更新有关。我不知道它是特定于设备还是会影响所有搭载 Android 11 的小米设备(希望不会)
-
感谢您的回答,您可以看一下这里,我发现这个article 在底部包含一个错误跟踪表。似乎他们确实在 Android 11 更新的通知方面存在问题。
-
有这方面的消息吗?我的应用也受到此问题的影响。
-
不...仍然崩溃:D
标签: android kotlin android-notifications xiaomi android-11