Javatpoint Logo
Javatpoint Logo

Cordova Plugin Vibration

The main task of this plugin is to vibrate the device. This plugin describes the global objects such as navigator.vibrate and aligns with the W3C vibration specification http://www.w3.org/TR/vibration/. If it is in the global scope, this plugin is not available until after the deviceready event.

The navigator.vibrate object is supported in various platforms such as Windows, iOS, Android.

Installation:

If you want to add this plugin in your app, you have to install it by typing the below command on command prompt:

vibrate

It is a method that consists of different functionalities based on the passed parameters.

Standard vibrate

If you want to specify the time to vibrate the device, you can easily do it through this particular functionality.

You can use any of the below syntax:

or

  • -time: It specifies the time in milliseconds to vibrate the device.

Example:

iOS quirks:

  • time: In the iOS platform, it vibrates for the pre-set amount of time and ignores the specified time by the user.

Example:

Windows Quirks:

  • time: It refers to the maximum time i.e., 5s and minimum time i.e.,

Example:

Vibrate with the pattern (For Android and Windows platform only):

It is only supported by the Android and Windows platforms. If you want to specify a pattern for vibrating the device, you can use it.

Parameter:

  • pattern: This parameter consists of an array of the numbers. It is specified by the user that consists of the sequence of duration represented in milliseconds. This sequence of duration can be used to turn on or turn off the vibration.

Example:

Cancel vibration (not supported in iOS platform):

It is used to immediately cancel the vibration that is currently running on the device.

or

or

The first syntax defines that we can pass the parameter 0 to cancel any vibration.

The second syntax defines that we can pass an empty array to cancel any vibration.

The third syntax defines that we can pass an empty array with the first element value 0 to cancel any vibration.

*notification.vibrate (deprecated)

If you want to specify the time to vibrate the device, you can easily do it by using the notification.vibrate.

Parameter:

  • time: It specifies the time in milliseconds to vibrate the device.

Example:

iOS quirks:

  • time: In the iOS platform, it vibrates for the pre-set amount of time and ignores the specified time by the user.

Example:

*notification.vibrateWithPattern (deprecated)

If you want to specify a pattern for vibrating the device, you can use the notification.vibrateWithPattern.

Parameter:

  • pattern: This parameter consists of an array of the numbers. It is specified by the user that consists of the sequence of duration represented in milliseconds. This sequence of duration can be used to turn on or turn off the vibration.
  • repeat: It consists of a number that defines the optional index into the pattern array at which it starts the repeating. It will repeat until it is canceled. The value -1 is for denoting the no repetition (default).

Example:

*notification.cancelVibration (deprecated)

It is used to immediately cancel the vibration that is currently running on the device.

Code:

HTML:

CSS:

JavaScript:

Output:

Cordova Plugin Vibration

When you click on any of the above buttons, you will be navigated to the particular webpage of Javatpoint.


Next TopicCordova Storage





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA