Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase messaging: default notification channel doesn't work

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?

like image 715
Maksim Ostrovidov Avatar asked Sep 01 '17 07:09

Maksim Ostrovidov


1 Answers

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.

like image 113
Diego Giorgini Avatar answered Sep 28 '22 16:09

Diego Giorgini