Firebase messaging: default notification channel doesn't work

Maksim Ostrovidov picture Maksim Ostrovidov · Sep 1, 2017 · Viewed 16.3k times · Source

When I send notifications from Firebase console without channel specified on Android Oreo it must use "Miscellaneous" channel OR if provided default channel from Android manifest. So I create and provide default channel in my app:

// Application onCreate
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val manager = getSystemService(Context.NOTIFICATION_SERVICE) 
            as NotificationManager
    val channelId = getString(R.string.notification_channel_id)
    if(manager.getNotificationChannel(channelId)==null) {
        val channel = NotificationChannel(channelId,
                getString(R.string.notification_channel_name),
                NotificationManager.IMPORTANCE_DEFAULT)
        channel.description = 
                getString(R.string.notification_channel_description)
        manager.createNotificationChannel(channel)
    }
}

// Manifest
<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel"
    android:value="@string/notification_channel_id" />

But it doesn't work. Notifications always use "Miscellaneous" channel. Am I missing something here or is it a Firebase bug?

Answer

Diego Giorgini picture Diego Giorgini · Sep 3, 2017

apologies, apparently the documentation has not been updated properly :(

The correct metadata in the manifest is:

<meta-data
   android:name="com.google.firebase.messaging.default_notification_channel_id"
   android:value="@string/notification_channel_id" />

Note the _id at the end of the android:name attribute value.

Will get the documentation updated asap.