简体   繁体   English

Firebase消息传递:默认通知通道不起作用

[英]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. 当我在没有在Android Oreo上指定的频道的情况下从Firebase控制台发送通知时,它必须使用“杂项”频道或者如果从Android清单提供默认频道。 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? 我在这里遗漏了什么或者它是Firebase的错误吗?

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. 注意android:name属性值末尾的_id

Will get the documentation updated asap. 将尽快更新文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM