我开始收到关于MIUI 11设备(仅限Mi10和Mi10 Lite 5G)运行Android 11的奇怪的崩溃报告。我认为这是平台问题,与我的应用程序无关,因为它非常特定于小米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通知引起的。
这是我用来创建通知的代码 (完整代码):
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())
有没有遇到相同的问题或知道解决方案?