# Print output for @column tags ?> Vibrator - Android SDK | Android Developers

Most visited

Recently visited

Vibrator

public abstract class Vibrator
extends Object

java.lang.Object
   ↳ android.os.Vibrator


Class that operates the vibrator on the device.

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

Summary

Constants

int VIBRATION_EFFECT_SUPPORT_NO

Vibration effect support: unsupported This effect is not supported by the underlying hardware.

int VIBRATION_EFFECT_SUPPORT_UNKNOWN

Vibration effect support: unknown The hardware doesn't report it's supported effects, so we can't determine whether the effect is supported or not.

int VIBRATION_EFFECT_SUPPORT_YES

Vibration effect support: supported This effect is supported by the underlying hardware.

Public methods

final int areAllEffectsSupported(int... effectIds)

Query whether the vibrator supports all of the given effects.

final boolean areAllPrimitivesSupported(int... primitiveIds)

Query whether the vibrator supports all of the given primitives.

int[] areEffectsSupported(int... effectIds)

Query whether the vibrator supports the given effects.

boolean[] arePrimitivesSupported(int... primitiveIds)

Query whether the vibrator supports the given primitives.

abstract void cancel()

Turn the vibrator off.

int getId()

Return the ID of this vibrator.

int[] getPrimitiveDurations(int... primitiveIds)

Query the estimated durations of the given primitives.

abstract boolean hasAmplitudeControl()

Check whether the vibrator has amplitude control.

abstract boolean hasVibrator()

Check whether the hardware has a vibrator.

void vibrate(long milliseconds)

This method is deprecated. Use vibrate(android.os.VibrationEffect) instead.

void vibrate(long[] pattern, int repeat)

This method is deprecated. Use vibrate(android.os.VibrationEffect) instead.

void vibrate(VibrationEffect vibe, AudioAttributes attributes)

Requires Manifest.permission.VIBRATE

void vibrate(long milliseconds, AudioAttributes attributes)

This method is deprecated. Use vibrate(android.os.VibrationEffect, android.media.AudioAttributes) instead.

void vibrate(VibrationEffect vibe)

Requires Manifest.permission.VIBRATE

void vibrate(long[] pattern, int repeat, AudioAttributes attributes)

This method is deprecated. Use vibrate(android.os.VibrationEffect, android.media.AudioAttributes) instead.

Inherited methods

Constants

VIBRATION_EFFECT_SUPPORT_NO

public static final int VIBRATION_EFFECT_SUPPORT_NO

Vibration effect support: unsupported This effect is not supported by the underlying hardware.

Constant Value: 2 (0x00000002)

VIBRATION_EFFECT_SUPPORT_UNKNOWN

public static final int VIBRATION_EFFECT_SUPPORT_UNKNOWN

Vibration effect support: unknown The hardware doesn't report it's supported effects, so we can't determine whether the effect is supported or not.

Constant Value: 0 (0x00000000)

VIBRATION_EFFECT_SUPPORT_YES

public static final int VIBRATION_EFFECT_SUPPORT_YES

Vibration effect support: supported This effect is supported by the underlying hardware.

Constant Value: 1 (0x00000001)

Public methods

areAllEffectsSupported

public final int areAllEffectsSupported (int... effectIds)

Query whether the vibrator supports all of the given effects. Not all hardware reports its effect capabilities, so the system may not necessarily know whether an effect is supported or not. If the result is VIBRATION_EFFECT_SUPPORT_YES, all effects in the query are supported by the hardware. If the result is VIBRATION_EFFECT_SUPPORT_NO, at least one of the effects in the query is not supported. If the result is VIBRATION_EFFECT_SUPPORT_UNKNOWN, the system doesn't know whether all of the effects are supported. It may support any or all of the queried effects, but there's no way to programmatically know whether a vibrate(VibrationEffect) call will successfully cause a vibration. It's guaranteed, however, that none of the queried effects are definitively unsupported by the hardware.

Parameters
effectIds int: Which effects to query for. This value cannot be null. Value is VibrationEffect.EFFECT_TICK, VibrationEffect.EFFECT_CLICK, VibrationEffect.EFFECT_HEAVY_CLICK, or VibrationEffect.EFFECT_DOUBLE_CLICK

Returns
int Whether all of the effects are supported. Value is VIBRATION_EFFECT_SUPPORT_UNKNOWN, VIBRATION_EFFECT_SUPPORT_YES, or VIBRATION_EFFECT_SUPPORT_NO

areAllPrimitivesSupported

public final boolean areAllPrimitivesSupported (int... primitiveIds)

Query whether the vibrator supports all of the given primitives.

Parameters
primitiveIds int: Which primitives to query for. This value cannot be null. Value is VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_THUD, VibrationEffect.Composition.PRIMITIVE_SPIN, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, VibrationEffect.Composition.PRIMITIVE_SLOW_RISE, VibrationEffect.Composition.PRIMITIVE_QUICK_FALL, VibrationEffect.Composition.PRIMITIVE_TICK, or VibrationEffect.Composition.PRIMITIVE_LOW_TICK

Returns
boolean Whether primitives effects are supported.

areEffectsSupported

public int[] areEffectsSupported (int... effectIds)

Query whether the vibrator supports the given effects. Not all hardware reports its effect capabilities, so the system may not necessarily know whether an effect is supported or not. The returned array will be the same length as the query array and the value at a given index will contain VIBRATION_EFFECT_SUPPORT_YES if the effect at that same index in the querying array is supported, VIBRATION_EFFECT_SUPPORT_NO if it isn't supported, or VIBRATION_EFFECT_SUPPORT_UNKNOWN if the system can't determine whether it's supported or not.

Parameters
effectIds int: Which effects to query for. This value cannot be null. Value is VibrationEffect.EFFECT_TICK, VibrationEffect.EFFECT_CLICK, VibrationEffect.EFFECT_HEAVY_CLICK, or VibrationEffect.EFFECT_DOUBLE_CLICK

Returns
int[] An array containing the systems current knowledge about whether the given effects are supported or not. This value cannot be null. Value is VIBRATION_EFFECT_SUPPORT_UNKNOWN, VIBRATION_EFFECT_SUPPORT_YES, or VIBRATION_EFFECT_SUPPORT_NO

arePrimitivesSupported

public boolean[] arePrimitivesSupported (int... primitiveIds)

Query whether the vibrator supports the given primitives. The returned array will be the same length as the query array and the value at a given index will contain whether the effect at that same index in the querying array is supported or not.

Parameters
primitiveIds int: Which primitives to query for. This value cannot be null. Value is VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_THUD, VibrationEffect.Composition.PRIMITIVE_SPIN, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, VibrationEffect.Composition.PRIMITIVE_SLOW_RISE, VibrationEffect.Composition.PRIMITIVE_QUICK_FALL, VibrationEffect.Composition.PRIMITIVE_TICK, or VibrationEffect.Composition.PRIMITIVE_LOW_TICK

Returns
boolean[] Whether the primitives are supported. This value cannot be null.

cancel

public abstract void cancel ()

Turn the vibrator off.
Requires Manifest.permission.VIBRATE

getId

public int getId ()

Return the ID of this vibrator.

Returns
int A non-negative integer representing the id of the vibrator controlled by this service, or -1 this service is not attached to any physical vibrator.

getPrimitiveDurations

public int[] getPrimitiveDurations (int... primitiveIds)

Query the estimated durations of the given primitives.

The returned array will be the same length as the query array and the value at a given index will contain the duration in milliseconds of the effect at the same index in the querying array.

The duration will be positive for primitives that are supported and zero for the unsupported ones, in correspondence with arePrimitivesSupported(int).

Parameters
primitiveIds int: Which primitives to query for. This value cannot be null. Value is VibrationEffect.Composition.PRIMITIVE_CLICK, VibrationEffect.Composition.PRIMITIVE_THUD, VibrationEffect.Composition.PRIMITIVE_SPIN, VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, VibrationEffect.Composition.PRIMITIVE_SLOW_RISE, VibrationEffect.Composition.PRIMITIVE_QUICK_FALL, VibrationEffect.Composition.PRIMITIVE_TICK, or VibrationEffect.Composition.PRIMITIVE_LOW_TICK

Returns
int[] The duration of each primitive, with zeroes for primitives that are not supported. This value cannot be null.

hasAmplitudeControl

public abstract boolean hasAmplitudeControl ()

Check whether the vibrator has amplitude control.

Returns
boolean True if the hardware can control the amplitude of the vibrations, otherwise false.

hasVibrator

public abstract boolean hasVibrator ()

Check whether the hardware has a vibrator.

Returns
boolean True if the hardware has a vibrator, else false.

vibrate

public void vibrate (long milliseconds)

This method is deprecated.
Use vibrate(android.os.VibrationEffect) instead.

Vibrate constantly for the specified period of time.
Requires Manifest.permission.VIBRATE

Parameters
milliseconds long: The number of milliseconds to vibrate.

vibrate

public void vibrate (long[] pattern, 
                int repeat)

This method is deprecated.
Use vibrate(android.os.VibrationEffect) instead.

Vibrate with a given pattern.

Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.

To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.


Requires Manifest.permission.VIBRATE

Parameters
pattern long: an array of longs of times for which to turn the vibrator on or off.

repeat int: the index into pattern at which to repeat, or -1 if you don't want to repeat.

vibrate

public void vibrate (VibrationEffect vibe, 
                AudioAttributes attributes)

Requires Manifest.permission.VIBRATE

Parameters
vibe VibrationEffect

attributes AudioAttributes

vibrate

public void vibrate (long milliseconds, 
                AudioAttributes attributes)

This method is deprecated.
Use vibrate(android.os.VibrationEffect, android.media.AudioAttributes) instead.

Vibrate constantly for the specified period of time.
Requires Manifest.permission.VIBRATE

Parameters
milliseconds long: The number of milliseconds to vibrate.

attributes AudioAttributes: AudioAttributes corresponding to the vibration. For example, specify AudioAttributes#USAGE_ALARM for alarm vibrations or AudioAttributes#USAGE_NOTIFICATION_RINGTONE for vibrations associated with incoming calls.

vibrate

public void vibrate (VibrationEffect vibe)

Requires Manifest.permission.VIBRATE

Parameters
vibe VibrationEffect

vibrate

public void vibrate (long[] pattern, 
                int repeat, 
                AudioAttributes attributes)

This method is deprecated.
Use vibrate(android.os.VibrationEffect, android.media.AudioAttributes) instead.

Vibrate with a given pattern.

Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.

To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.


Requires Manifest.permission.VIBRATE

Parameters
pattern long: an array of longs of times for which to turn the vibrator on or off.

repeat int: the index into pattern at which to repeat, or -1 if you don't want to repeat.

attributes AudioAttributes: AudioAttributes corresponding to the vibration. For example, specify AudioAttributes#USAGE_ALARM for alarm vibrations or AudioAttributes#USAGE_NOTIFICATION_RINGTONE for vibrations associated with incoming calls.