I have an app that receives notifications trough Firebase Cloud Messaging, I have a Service that is in charge of that and a few days ago I started getting a lot of Firebase (Crashlytics) report of the following error:
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=NotificationServiceId pri=-1 contentView=null vibrate=null sound=null defaults=0x0 flags=0x72 color=0x00000000 vis=SECRET)
Apparently this is a problem that only happens in Huawei devices with Android 8, 9 and 10. I've read some solutions that said you should create a new channel for Android 8 and above but I already had that in my app. This error appeared from nowhere since I haven't change that Service in a while, here is my code
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())
I tryed to replicate the error sending a test notification to a Huawei mate 20 pro device with Android 10 and everything worked as expected, the notification arrived fine and the app opened well so, I don't really know if this is a real bug from Firebase or how to replicate it correctly.
I would really appreciate if someone has information about this error! Thanks