Как отменить уведомление о пожарной базе? - PullRequest
0 голосов
/ 16 января 2020

Я пытаюсь отменить уведомление, которое содержит 30-секундный шаблон вибрации.

val notificationBuilder = NotificationCompat.Builder(this, channelId)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle(getString(R.string.visit_arrived))
        .setContentText(messageBody)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent)
        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
        .setVibrate(longArrayOf(
            0,
            5000,
            1000,
            5000,
            1000,
            5000,
            1000,
            5000,
            1000,
            5000,
            1000)
        )
        .setDefaults(Notification.DEFAULT_ALL)

Но когда вы пытаетесь отменить его через 30 секунд, оно все еще активно. Возможно ли это с помощью тега FLAG_INSISTENT?

notificationManager.notify(
        INTERCOM_NOTIFICATION,
        INTERCOM_NOTIFICATION_ID,
        notificationBuilder.build().also {
            it.flags =
                it.flags or Notification.FLAG_INSISTENT or Notification.FLAG_AUTO_CANCEL
        })

    Handler().postDelayed({
        notificationManager.cancel(
            INTERCOM_NOTIFICATION,
            INTERCOM_NOTIFICATION_ID
        )
    }, 30000)
...