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 を搭載した Huawei デバイスでのみ発生する問題です。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 を搭載した Huawei mate 20 pro デバイスにテスト通知を送信するエラーを再現しようとしましたが、すべてが期待どおりに機能し、通知が正常に届き、アプリが正常に開いたので、これが本当のバグであるかどうかはわかりませんFirebase またはそれを正しく複製する方法。
誰かがこのエラーに関する情報を持っていれば、本当に感謝しています! ありがとう