Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/os/VibrationEffect#nestedclasses) \| [Constants](https://developer.android.com/reference/android/os/VibrationEffect#constants) \| [Inherited Constants](https://developer.android.com/reference/android/os/VibrationEffect#inhconstants) \| [Fields](https://developer.android.com/reference/android/os/VibrationEffect#lfields) \| [Methods](https://developer.android.com/reference/android/os/VibrationEffect#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/VibrationEffect#inhmethods)

# VibrationEffect

*** ** * ** ***


`
public


abstract
class
VibrationEffect
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/android/os/Parcelable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.VibrationEffect |

<br />

*** ** * ** ***

A VibrationEffect describes a haptic effect to be performed by a `https://developer.android.com/reference/android/os/Vibrator`.

These effects may be any number of things, from single shot vibrations to complex waveforms.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.BasicEnvelopeBuilder` A builder for waveform effects defined by their envelope, designed to provide a consistent haptic perception across devices with varying capabilities. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.Builder` A builder for composing haptic effects by sequencing various haptic elements. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition` A composition of haptic elements that are combined to be playable as a single `https://developer.android.com/reference/android/os/VibrationEffect`. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.Envelope` Represents a haptic effect defined by an envelope, to be used within a `https://developer.android.com/reference/android/os/VibrationEffect.Builder`. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.Event` Represents a single event in a vibration composition with a start time relative to the start of the composition. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.Preset` Represents a predefined haptics pattern, corresponding to `https://developer.android.com/`. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.VibrationParseException` Exception thrown when parsing a vibration XML fails due to invalid format or values. |
| ` class` | `https://developer.android.com/reference/android/os/VibrationEffect.WaveformEnvelopeBuilder` A builder for waveform effects described by its envelope. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect#DEFAULT_AMPLITUDE` The default vibration strength of the device. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK` A click effect. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_DOUBLE_CLICK` A double click effect. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_HEAVY_CLICK` A heavy click effect. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_TICK` A tick effect. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that
the Parcelable object's flattened representation includes a file descriptor.


`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written
is a return value, that is the result of a function such as
"`Parcelable someFunction()`",
"`void someFunction(out Parcelable)`", or
"`void someFunction(inout Parcelable)`".


| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/os/VibrationEffect>` | `https://developer.android.com/reference/android/os/VibrationEffect#CREATOR` |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createOneShot(long,%20int)(long milliseconds, int amplitude) ` Create a one shot vibration. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createPredefined(int)(int effectId) ` Create a predefined vibration effect. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createRepeatingEffect(android.os.VibrationEffect,%20android.os.VibrationEffect)(https://developer.android.com/reference/android/os/VibrationEffect preamble, https://developer.android.com/reference/android/os/VibrationEffect repeatingEffect) ` Creates a new `https://developer.android.com/reference/android/os/VibrationEffect` by merging the preamble and repeating vibration effect. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createRepeatingEffect(android.os.VibrationEffect)(https://developer.android.com/reference/android/os/VibrationEffect effect) ` Creates a new `https://developer.android.com/reference/android/os/VibrationEffect` that repeats the given effect indefinitely. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createWaveform(long[],%20int[],%20int)(long[] timings, int[] amplitudes, int repeat) ` Create a waveform vibration. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#createWaveform(long[],%20int)(long[] timings, int repeat) ` Create a waveform vibration, using only off/on transitions at the provided time intervals, and potentially repeating. |
| ` int` | ` https://developer.android.com/reference/android/os/VibrationEffect#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` abstract https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/os/VibrationEffect.Event>` | ` https://developer.android.com/reference/android/os/VibrationEffect#getEvents()() ` Returns a list of `https://developer.android.com/reference/android/os/VibrationEffect.Event`s that make up this effect. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect#parseFromXml(java.io.InputStream)(https://developer.android.com/reference/java/io/InputStream inputStream) ` Parses a `https://developer.android.com/reference/android/os/VibrationEffect` from an XML input stream. |
| ` static https://developer.android.com/reference/android/os/VibrationEffect.Composition` | ` https://developer.android.com/reference/android/os/VibrationEffect#startComposition()() ` Start composing a haptic effect. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


From interface `

https://developer.android.com/reference/android/os/Parcelable

` `
abstract


int` `
https://developer.android.com/reference/android/os/Parcelable#describeContents()()
`

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


`
abstract


void` `
https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags)
`

Flatten this object in to a Parcel.


## Constants

### DEFAULT_AMPLITUDE

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFAULT_AMPLITUDE
```

The default vibration strength of the device.

<br />

Constant Value:

-1
(0xffffffff)


### EFFECT_CLICK

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int EFFECT_CLICK
```

A click effect. Use this effect as a baseline, as it's the most common type of click effect.

<br />

Constant Value:

0
(0x00000000)


### EFFECT_DOUBLE_CLICK

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int EFFECT_DOUBLE_CLICK
```

A double click effect.

<br />

Constant Value:

1
(0x00000001)


### EFFECT_HEAVY_CLICK

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int EFFECT_HEAVY_CLICK
```

A heavy click effect. This effect is stronger than `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK`.

<br />

Constant Value:

5
(0x00000005)


### EFFECT_TICK

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int EFFECT_TICK
```

A tick effect. This effect is less strong compared to `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK`.

<br />

Constant Value:

2
(0x00000002)


## Fields

### CREATOR

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<VibrationEffect> CREATOR
```

<br />

<br />

## Public methods

### createOneShot

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static 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.

<br />

| Parameters ||
|---|---|
| `milliseconds` | `long`: The number of milliseconds to vibrate. This must be a positive number. <br /> |
| `amplitude` | `int`: The strength of the vibration. This must be a value between 1 and 255, or `https://developer.android.com/reference/android/os/VibrationEffect#DEFAULT_AMPLITUDE`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | The desired effect. <br /> |

### createPredefined

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static VibrationEffect createPredefined (int effectId)
```

Create a predefined vibration effect.

Predefined effects are a set of common vibration effects that should be identical,
regardless of the app they come from, in order to provide a cohesive experience for users
across the entire device. They also may be custom tailored to the device hardware in order to
provide a better experience than you could otherwise build using the generic building
blocks.

This will fallback to a generic pattern if one exists and there does not exist a
hardware-specific implementation of the effect.

<br />

| Parameters ||
|---|---|
| `effectId` | `int`: The ID of the effect to perform: `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK`, `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_DOUBLE_CLICK`, `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_TICK` Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_TICK` - `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_HEAVY_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_DOUBLE_CLICK` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | The desired effect. This value cannot be `null`. <br /> |

### createRepeatingEffect

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static VibrationEffect createRepeatingEffect (VibrationEffect preamble, 
                VibrationEffect repeatingEffect)
```

Creates a new `https://developer.android.com/reference/android/os/VibrationEffect` by merging the preamble and repeating vibration effect.

Neither input vibration may already be repeating. An `https://developer.android.com/reference/java/lang/IllegalArgumentException` will
be thrown if either input vibration is set to repeat indefinitely.

If this method is invoked with mixed effects (one timelined and one legacy), the legacy
effect will be converted into a timelined effect. When converting, the effect's duration is
estimated, but this estimation is best-effort and may lead to hardware-dependent timing
variations. In such cases, the `https://developer.android.com/reference/android/os/VibrationEffect.Builder#setRepeatingEffect(long,%20android.os.VibrationEffect,%20long)` method is preferred as it allows for explicit control over the timing of the repeating
part.

<br />

| Parameters ||
|---|---|
| `preamble` | `VibrationEffect`: The starting vibration effect, which must be finite. This value cannot be `null`. <br /> |
| `repeatingEffect` | `VibrationEffect`: The vibration effect to be repeated indefinitely after the preamble. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | A `https://developer.android.com/reference/android/os/VibrationEffect` that plays the preamble once followed by the \`repeatingEffect\` indefinitely. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if either preamble or repeatingEffect is already a repeating vibration. |

### createRepeatingEffect

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static VibrationEffect createRepeatingEffect (VibrationEffect effect)
```

Creates a new `https://developer.android.com/reference/android/os/VibrationEffect` that repeats the given effect indefinitely.

The input vibration must not be a repeating vibration. If it is, an
`https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown.

<br />

| Parameters ||
|---|---|
| `effect` | `VibrationEffect`: The `https://developer.android.com/reference/android/os/VibrationEffect` that will be repeated. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | A `https://developer.android.com/reference/android/os/VibrationEffect` that repeats the effect indefinitely. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the effect is already a repeating vibration. |

### createWaveform

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Create a waveform vibration.

Waveform vibrations are a potentially repeating series of timing and amplitude pairs,
provided in separate arrays. 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, in milliseconds.

To cause the pattern to repeat, pass the index into the timings array at which to start
the repetition, or -1 to disable repeating. Repeating effects will be played indefinitely
and should be cancelled via `https://developer.android.com/reference/android/os/Vibrator#cancel()`.

<br />

| Parameters ||
|---|---|
| `timings` | `long`: The timing values, in milliseconds, of the timing / amplitude pairs. Timing values of 0 will cause the pair to be ignored. <br /> |
| `amplitudes` | `int`: The amplitude values of the timing / amplitude pairs. Amplitude values must be between 0 and 255, or equal to `https://developer.android.com/reference/android/os/VibrationEffect#DEFAULT_AMPLITUDE`. An amplitude value of 0 implies the motor is off. <br /> |
| `repeat` | `int`: The index into the timings array at which to repeat, or -1 if you don't want to repeat indefinitely. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | The desired effect. <br /> |

### createWaveform

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Create a waveform vibration, using only off/on transitions at the provided time intervals,
and potentially repeating.

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.

This method is equivalent to calling `https://developer.android.com/reference/android/os/VibrationEffect#createWaveform(long[],%20int[],%20int)` with
corresponding amplitude values alternating between 0 and `https://developer.android.com/reference/android/os/VibrationEffect#DEFAULT_AMPLITUDE`,
beginning with 0.

To cause the pattern to repeat, pass the index into the timings array at which to start
the repetition, or -1 to disable repeating. Repeating effects will be played indefinitely
and should be cancelled via `https://developer.android.com/reference/android/os/Vibrator#cancel()`.

<br />

| Parameters ||
|---|---|
| `timings` | `long`: The pattern of alternating on-off timings, starting with an 'off' timing, and representing the length of time to sustain the individual item (not cumulative). <br /> |
| `repeat` | `int`: The index into the timings array at which to repeat, or -1 if you don't want to repeat indefinitely. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | The desired effect. <br /> |

### describeContents

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`,
the return value of this method must include the
`https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getEvents

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public abstract List<VibrationEffect.Event> getEvents ()
```

Returns a list of `https://developer.android.com/reference/android/os/VibrationEffect.Event`s that make up this effect. This effect must
NOT be a repeating effect.

This method is used to retrieve the constituent events from a `https://developer.android.com/reference/android/os/VibrationEffect`,
primarily for use with `https://developer.android.com/reference/android/os/VibrationEffect.Builder`.

If this effect was created via the `https://developer.android.com/reference/android/os/VibrationEffect.Composition` API, then each primitive will be
converted into an event. The start time for each event is calculated using the primitive
delay and an estimated duration for all preceding primitives. These estimates are based on
the recommended primitive duration targets from [Android Haptics Constants](https://source.android.com/docs/core/interaction/haptics/haptics-constants-primitives). The estimates used are:
- 12ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK`,
- 5ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK`,
- 12ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK`,
- 500ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE`,
- 150ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE`,
- 100ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL`,
- 300ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD`,
- 150ms for `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN`.

Actual primitive durations may differ between devices.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/os/VibrationEffect.Event>` | A list of events. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the effect is a repeating effect. |
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if this effect type cannot be represented as a list of events. |

### parseFromXml

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static VibrationEffect parseFromXml (InputStream inputStream)
```

Parses a `https://developer.android.com/reference/android/os/VibrationEffect` from an XML input stream.

This method is suitable for dynamic or real-time use cases, such as loading vibration
patterns from a network download, external storage, or strings generated on the fly in
memory.

For static vibration patterns bundled inside the application package, see
`https://developer.android.com/reference/android/view/VibrationEffectInflater#from(android.content.Context)`.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `inputStream` | `InputStream`: The input stream containing the XML. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | Parsed `https://developer.android.com/reference/android/os/VibrationEffect`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.VibrationParseException` | If there's a parsing error. |
| `https://developer.android.com/reference/java/io/IOException` |   |

### startComposition

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static VibrationEffect.Composition startComposition ()
```

Start composing a haptic effect.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.Composition` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/VibrationEffect.Composition`