gpt4 book ai didi

java - 是否需要检查通知 channel 是否已创建?

转载 作者:行者123 更新时间:2023-12-02 01:09:11 24 4
gpt4 key购买 nike

在创建通知 channel 之前我们是否需要检查它是否尚未创建?

 private fun createChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// todo: add here check if channel is already created
val defaultChannel = NotificationChannel(MEDIA_UPLOAD_NOTIFICATION_CHANNEL_ID, MEDIA_UPLOAD_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)
defaultChannel.description = MEDIA_UPLOAD_NOTIFICATION_CHANNEL_DESC
defaultChannel.enableVibration(true)
notificationManager.createNotificationChannel(defaultChannel)
}
}

最佳答案

不,您实际上不必检查这一点。如果存在具有相同 ID 的 channel ,则 Android 不会创建另一个 channel 。

根据文档

Creating an existing notification channel with its original values performs no operation, so it's safe to call this code when starting an app.

更多信息请访问 https://developer.android.com/training/notify-user/channels#CreateChannel

关于java - 是否需要检查通知 channel 是否已创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59610432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com