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

Mak*_*dov 8 android push-notification firebase firebase-cloud-messaging android-8.0-oreo

当我在没有在Android Oreo上指定的频道的情况下从Firebase控制台发送通知时,它必须使用"杂项"频道或者如果从Android清单提供默认频道.所以我在我的应用中创建并提供默认频道:

// 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" />
Run Code Online (Sandbox Code Playgroud)

但它不起作用.通知始终使用"杂项"频道.我在这里遗漏了什么或者它是Firebase的错误吗?

Die*_*ini 14

道歉,显然文档没有正确更新:(

清单中的正确元数据是:

<meta-data
   android:name="com.google.firebase.messaging.default_notification_channel_id"
   android:value="@string/notification_channel_id" />
Run Code Online (Sandbox Code Playgroud)

请注意属性值_id的末尾android:name.

将尽快更新文档.

  • 你如何创建**notification_channel_id** (6认同)
  • 现在可以了,谢谢。我交付了 PR 并修复了 faststart-android 存储库。 (2认同)
  • @MaheshGawhane &lt;string name =“ default_notification_channel_id”&gt;默认&lt;/ string&gt; (2认同)