Firebase 消息传递:默认通知渠道不起作用
Firebase messaging: default notification channel doesn't work
当我在 Android Oreo 上没有指定频道的情况下从 Firebase 控制台发送通知时,它必须使用 "Miscellaneous" 频道 或者 如果提供了来自 [=19] 的默认频道=] 清单。所以我在我的应用程序中创建并提供了默认频道:
// 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" />
但是没用。通知始终使用 "Miscellaneous" 渠道。我是不是遗漏了什么或者是 Firebase 错误?
抱歉,显然文档没有正确更新:(
清单中正确的元数据是:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
注意 android:name
属性值末尾的 _id
。
将尽快更新文档。
当我在 Android Oreo 上没有指定频道的情况下从 Firebase 控制台发送通知时,它必须使用 "Miscellaneous" 频道 或者 如果提供了来自 [=19] 的默认频道=] 清单。所以我在我的应用程序中创建并提供了默认频道:
// 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" />
但是没用。通知始终使用 "Miscellaneous" 渠道。我是不是遗漏了什么或者是 Firebase 错误?
抱歉,显然文档没有正确更新:(
清单中正确的元数据是:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
注意 android:name
属性值末尾的 _id
。
将尽快更新文档。