Added in API level 31

VibratorManager


abstract class VibratorManager
kotlin.Any
   ↳ android.os.VibratorManager

Provides access to all vibrators from the device, as well as the ability to run them in a synchronized fashion.

If your process exits, any vibration you started will stop.

Summary

Public methods
abstract Unit

Turn all the vibrators off.

abstract Vibrator

Returns the default Vibrator for the device.

abstract Vibrator
getVibrator(vibratorId: Int)

Retrieve a single vibrator by id.

abstract IntArray

List all available vibrator ids, returning a possible empty list.

Unit

Vibrate with a given combination of effects.

Unit

Vibrate with a given combination of effects.

Public methods

cancel

Added in API level 31
abstract fun cancel(): Unit

Turn all the vibrators off.
Requires android.Manifest.permission#VIBRATE

getDefaultVibrator

Added in API level 31
abstract fun getDefaultVibrator(): Vibrator

Returns the default Vibrator for the device.

Return
Vibrator This value cannot be null.

getVibrator

Added in API level 31
abstract fun getVibrator(vibratorId: Int): Vibrator

Retrieve a single vibrator by id.

Parameters
vibratorId Int: The id of the vibrator to be retrieved.
Return
Vibrator The vibrator with given vibratorId, never null.

getVibratorIds

Added in API level 31
abstract fun getVibratorIds(): IntArray

List all available vibrator ids, returning a possible empty list.

Return
IntArray An array containing the ids of the vibrators available on the device. This value cannot be null.

vibrate

Added in API level 31
fun vibrate(effect: CombinedVibration): Unit

Vibrate with a given combination of effects.

Pass in a CombinedVibration representing a combination of VibrationEffects to be played on one or more vibrators.

The app should be in foreground for the vibration to happen.


Requires android.Manifest.permission#VIBRATE
Parameters
effect CombinedVibration: a combination of effects to be performed by one or more vibrators. This value cannot be null.

vibrate

Added in API level 31
fun vibrate(
    effect: CombinedVibration,
    attributes: VibrationAttributes?
): Unit

Vibrate with a given combination of effects.

Pass in a CombinedVibration representing a combination of VibrationEffect to be played on one or more vibrators.

The app should be in foreground for the vibration to happen. Background apps should specify a ringtone, notification or alarm usage in order to vibrate.


Requires android.Manifest.permission#VIBRATE
Parameters
effect CombinedVibration: a combination of effects to be performed by one or more vibrators. This value cannot be null.
attributes VibrationAttributes?: VibrationAttributes corresponding to the vibration. For example, specify VibrationAttributes#USAGE_ALARM for alarm vibrations or VibrationAttributes#USAGE_RINGTONE for vibrations associated with incoming calls. This value may be null.