Skip to content

Most visited

Recently visited

navigation

VibrationEffect

public abstract class VibrationEffect
extends Object implements Parcelable

java.lang.Object
   ↳ android.os.VibrationEffect


A VibrationEffect describes a haptic effect to be performed by a Vibrator. These effects may be any number of things, from single shot vibrations to complex waveforms.

Summary

Constants

int DEFAULT_AMPLITUDE

The default vibration strength of the device.

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<VibrationEffect> CREATOR

Public methods

static VibrationEffect createOneShot(long milliseconds, int amplitude)

Create a one shot vibration.

static VibrationEffect createWaveform(long[] timings, int[] amplitudes, int repeat)

Create a waveform vibration.

static VibrationEffect createWaveform(long[] timings, int repeat)

Create a waveform vibration.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Constants

DEFAULT_AMPLITUDE

added in API level 26
int DEFAULT_AMPLITUDE

The default vibration strength of the device.

Constant Value: -1 (0xffffffff)

Fields

CREATOR

added in API level 26
Creator<VibrationEffect> CREATOR

Public methods

createOneShot

added in API level 26
VibrationEffect createOneShot (long milliseconds, 
                int amplitude)

Create a one shot vibration. One shot vibrations will vibrate constantly for the specified period of time at the specified amplitude, and then stop.

Parameters
milliseconds long: The number of milliseconds to vibrate. This must be a positive number.

amplitude int: The strength of the vibration. This must be a value between 1 and 255, or DEFAULT_AMPLITUDE.

Returns
VibrationEffect The desired effect.

createWaveform

added in API level 26
VibrationEffect createWaveform (long[] timings, 
                int[] amplitudes, 
                int repeat)

Create a waveform vibration. Waveform vibrations are a potentially repeating series of timing and amplitude pairs. For each pair, the value in the amplitude array determines the strength of the vibration and the value in the timing array determines how long it vibrates for. An amplitude of 0 implies no vibration (i.e. off), and any pairs with a timing value of 0 will be ignored.

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

Parameters
timings long: The timing values of the timing / amplitude pairs. Timing values of 0 will cause the pair to be ignored.

amplitudes int: The amplitude values of the timing / amplitude pairs. Amplitude values must be between 0 and 255, or equal to DEFAULT_AMPLITUDE. An amplitude value of 0 implies the motor is off.

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

Returns
VibrationEffect The desired effect.

createWaveform

added in API level 26
VibrationEffect createWaveform (long[] timings, 
                int repeat)

Create a waveform vibration. Waveform vibrations are a potentially repeating series of timing and amplitude pairs. For each pair, the value in the amplitude array determines the strength of the vibration and the value in the timing array determines how long it vibrates for. An amplitude of 0 implies no vibration (i.e. off), and any pairs with a timing value of 0 will be ignored.

The amplitude array of the generated waveform will be the same size as the given timing array with alternating values of 0 (i.e. off) and DEFAULT_AMPLITUDE, starting with 0. Therefore the first timing value will be the period to wait before turning the vibrator on, the second value will be how long to vibrate at DEFAULT_AMPLITUDE strength, etc.

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

Parameters
timings long: The pattern of alternating on-off timings, starting with off. Timing values of 0 will cause the timing / amplitude pair to be ignored.

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

Returns
VibrationEffect The desired effect.

describeContents

added in API level 26
int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)