vibrateCompat

@RequiresPermission(value = "android.permission.VIBRATE")
fun Vibrator.vibrateCompat(lengthMs: Long, usage: Int, amplitude: Int? = null)

Vibrates using this Vibrator for lengthMs milliseconds.

Parameters

usage

required which is defined in VibrationAttributes.

amplitude

is defined in VibrationEffect. When null, VibrationEffect.DEFAULT_AMPLITUDE will be used.


@RequiresPermission(value = "android.permission.VIBRATE")
fun Vibrator.vibrateCompat(waveform: LongArray, usage: Int, repeat: Int = -1)

Vibrates using this Vibrator using provided waveform.

In effect, the timings array represents the number of milliseconds before turning the vibrator on, followed by the number of milliseconds to keep the vibrator on, then the number of milliseconds turned off, and so on. Consequently, the first timing value will often be 0, so that the effect will start vibrating immediately.

Parameters

usage

required which is defined in VibrationAttributes.

repeat

the index into the waveform, at which to start indefinite repetitions of the vibration, where -1 means no repeat. If you pass anything but -1 there, you must cancel the vibration manually by calling Vibrator.cancel