Я обслуживаю приложение с 1 года go.
Я сделал createNotificationChannel , setChannelId и startForeground для служба переднего плана, и я использую один и тот же идентификатор канала и имя для двух служб.
До февраля все работало нормально.
private var notificationBuilder: Notification.Builder? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
var channel = notificationManager.getNotificationChannel(notificationChannelId)
if (channel == null) {
channel = NotificationChannel(notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_MIN)
notificationManager.createNotificationChannel(channel)
}
if (notificationBuilder == null || startForeground) {
notificationBuilder = Notification.Builder(service, channel.id)
.setSmallIcon(R.drawable.my_icon)
.setColor(ResourcesCompat.getColor(service.resources, R.color.my_color, null))
.setOnlyAlertOnce(true)
.setContentText(notificationMessage)
.setContentIntent(notiClickPendingIntent)
.setChannelId(notificationChannelId)
val notiBuilder = notificationBuilder ?: return
service.startForeground(notificationID, notiBuilder.build())
} else {
// update notification
val notiBuilder = notificationBuilder ?: return
notiBuilder
.setContentText(notificationMessage)
.setChannelId(notificationChannelId)
notificationManager.notify(notificationID, notiBuilder.build())
}
}
В последнее время, хотя я не изменил соответствующие код, отчеты об ошибках начали появляться с марта.
Bad notification for startForeground: java.lang.IllegalArgumentException: Channel does not exist
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification
Эти ошибки в подавляющем большинстве случаев встречаются в Android 10, и часто встречаются в Android 9.
И это произошло много в серии Galaxy s10 и серии Galaxy Note 10.
Кто-нибудь знает какую-либо соответствующую информацию?
ps Я был бы очень признателен, если бы вы могли дать мне лучший Engli sh выражение!