如何为应用程序在后台时出现的通知消息设置默认通知通道?默认情况下,这些消息使用"杂项"通道.
当我在没有在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的错误吗?
android push-notification firebase firebase-cloud-messaging android-8.0-oreo