Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set repeating times of vibration pattern of a Notification Chanel for Android SDK 26

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.

like image 383
MeLean Avatar asked Oct 29 '25 08:10

MeLean


1 Answers

use this :

notification.flags = Notification.FLAG_INSISTENT

before putting into NotificationManager.notify

like image 85
REXWAN Avatar answered Oct 30 '25 21:10

REXWAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!