【发布时间】: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