【问题标题】:Firebase messaging: default notification channel doesn't workFirebase 消息传递:默认通知渠道不起作用
【发布时间】:2023-03-08 21:46:01
【问题描述】:

当我从 Firebase 控制台发送通知而未在 Android Oreo 上指定频道时,如果从 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" />

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

【问题讨论】:

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


    【解决方案1】:

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

    清单中正确的元数据是:

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

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

    将尽快更新文档。

    【讨论】:

    • 现在可以了,谢谢。我向 quickstart-android repo 提交了带有修复程序的 PR。
    • 如何创建notification_channel_id
    • @MaheshGawhane 默认
    猜你喜欢
    • 2020-08-14
    • 1970-01-01
    • 2019-07-05
    • 2018-02-13
    • 2020-09-01
    • 2020-06-06
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多