В android 10 я использую уведомление типа ответа. Я хочу очистить это уведомление об ответном действии. Для очистки уведомления я использую этот код:
val notificationManager =
context.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(notifyId)
Для переменной notifyId я передаю идентификатор уведомления.
этот код работает для всех android версии за исключением android версия 10.
Используется для создания действия ответа:
val replyAction = NotificationCompat.Action.Builder(
R.drawable.ic_send,
btnlable,
getReplyPendingIntent(
notificationId,
title,
msg,
senderName,
action,
apiName,
type,
intentType
)
)
.addRemoteInput(remoteInput)
.setAllowGeneratedReplies(true)
.build()
Используется для создания уведомления:
val notification = NotificationCompat.Builder(mContext, channelID)
.setSmallIcon(R.drawable.noti_icon)
.setContentTitle(title) //Set the title of Notification
.setContentText(msg) //Set the text for notification
.addAction(replyAction)
.setSound(null)
.setWhen(getTimeMilliSec(timeStamp))
.setLargeIcon(BitmapFactory.decodeResource(mContext.resources, R.drawable.logo))
.setContentIntent(resultPendingIntent)
.build();
notification.flags = Notification.FLAG_AUTO_CANCEL