我有一个通过 Firebase Cloud Messaging 接收通知的应用程序,我有一个负责该通知的服务,几天前我开始收到很多关于以下错误的 Firebase (Crashlytics) 报告:
startForeground 的错误通知:java.lang.RuntimeException:服务通知的无效通道:Notification(channel=NotificationServiceId pri=-1 contentView=null vibrate=null sound=null defaults=0x0 flags=0x72 color=0x00000000 vis=SECRET)
显然,这个问题只发生在搭载 Android 8、9 和 10 的华为设备中。我读过一些解决方案,说您应该为 Android 8 及更高版本创建一个新频道,但我的应用程序中已经有了。这个错误不知从何而来,因为我有一段时间没有更改该服务,这是我的代码
val pendingIntent = PendingIntent.getActivity(
this, (System.currentTimeMillis()).toInt(), intent,
PendingIntent.FLAG_UPDATE_CURRENT)
val channelId = getString(com.kubo.leal.R.string.notification_channel_id)
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(com.kubo.leal.R.drawable.logo_leal)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH
)
notificationManager.createNotificationChannel(channel)
notificationBuilder.setChannelId(channelId)
}
notificationManager.notify(0, notificationBuilder.build())
我尝试复制错误,向配备 Android 10 的华为 mate 20 pro 设备发送测试通知,一切正常,通知到达正常,应用程序打开良好,我真的不知道这是否是一个真正的错误Firebase 或如何正确复制它。
如果有人知道有关此错误的信息,我将不胜感激!谢谢