Firebase messaging: default notification channel doesn't work

*爱你&永不变心* 提交于 2019-12-08 19:14:27

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/45995337/firebase-messaging-default-notification-channel-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!