4

I am trying to use a custom vibration on local notifications. After reading a bit I set the custom vibration pattern in the Notification Channel, like this:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val notificationChannel =
            NotificationChannel(NotificationChannels.CHANNEL_ID, channelName, importance)

        ...

        notificationChannel.enableVibration(true)
        notificationChannel.vibrationPattern = vibrationPattern
        notificationManager.createNotificationChannel(notificationChannel)
    }

But it vibrates only once and executes only the first four indexes.

For example, if my pattern looks like this:

val vibrationPattern = longArrayOf(
        0, 200, 500, 50,
        0, 200, 500, 50,
        0, 200, 500, 50,
        0, 200, 500, 50,
        0, 200, 500, 50,
        0, 200, 500, 50)

It vibrates only regarding the first row and stops. The vibrations are equivalent to this:

val vibrationPattern = longArrayOf(0, 200, 500, 50)

I had an idea to set the pattern to look like the last one and to set the system to repeat it several times, but I did not find how to do it so far.

I will be glad to get some help here.

MeLean
  • 3,092
  • 6
  • 29
  • 43

1 Answers1

6

use this :

notification.flags = Notification.FLAG_INSISTENT

before putting into NotificationManager.notify

I_love_vegetables
  • 1,575
  • 5
  • 12
  • 26
REXWAN
  • 61
  • 1
  • 2
  • vibration does not stop after cancelling notification. It does not stop even after force stopping the app. The sound stops. Could you please help? – Daniil Andashev May 15 '23 at 15:31