android - Firebase 消息传递 : default notification channel doesn't work

标签 android firebase push-notification firebase-cloud-messaging android-8.0-oreo

当我在 Android Oreo 上没有指定 channel 的情况下从 Firebase 控制台发送通知时,它必须使用“杂项” channel 如果提供了来自 Android list 的默认 channel 。所以我在我的应用程序中创建并提供了默认 channel :

// 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" />

但它不起作用。通知始终使用“杂项” channel 。我在这里遗漏了什么还是 Firebase 错误?

最佳答案

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

list 中正确的元数据是:

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

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

将尽快更新文档。

关于android - Firebase 消息传递 : default notification channel doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45995337/

相关文章:

android - 所有通知都来自服务器?

android - 更改市场名称

firebase - Firestore 集合查询作为 Flutter 中的流

android - FireBase Firestore 按 ID 列表检索多个文档

json - 如何通过 firebase 托管将我的主页重定向到随机 url?

android - 在 Android 中使用外部声音推送通知

android - 注销新的 Google Cloud Messaging

android - 三星A6+对应什么(对比BrowserStack)和css媒体查询?

android - 安全存储的限制 - KeyChain 和 KeyStore

android - 设计 View 中的数据绑定(bind)