DedrisFrameworkDedrisFramework

← Plugins  /  Vibration

📳

Vibration

cordova-plugin-vibration
iOS Android

This Apache Cordova plugin lets your app deliver haptic feedback — a single buzz or a custom rhythm of buzzes. It's a simple way to confirm an action, flag an alert, or add tactile punch to a game.

Installation

Add the plugin to your Cordova project from the command line:

terminal
cordova plugin add cordova-plugin-vibration

Methods

The plugin extends the global navigator object with a vibrate function. Call it after deviceready has fired:

CallDescription
navigator.vibrate(time)Vibrates for time milliseconds.
navigator.vibrate([t1, t2, t3, ...])Plays an Android pattern of alternating wait and vibrate durations, in milliseconds.
navigator.vibrate(0) or navigator.vibrate([])Cancels any vibration that is currently running (Android).

Platform note

On iOS the duration and any pattern are disregarded — the device always plays its single, standard short vibration. Custom patterns and cancellation are available on Android only.

Usage example

Fire a quick confirmation buzz, or play a short two-part pattern:

www/js/app.js
document.addEventListener("deviceready", onReady, false);

function onReady() {
  // A quick confirmation buzz
  navigator.vibrate(200);

  // An Android pattern: wait 0ms, buzz 200ms, wait 100ms, buzz 200ms
  navigator.vibrate([0, 200, 100, 200]);
}

Tips

📚 Source: the technical reference on this page (the vibrate calls, pattern behavior, platform notes and the install command) is based on the official Apache Cordova vibration documentation. Descriptions and examples have been rewritten in DedrisFramework's own words. Apache Cordova documentation is published by the Apache Software Foundation under the Apache License 2.0.
← Back to plugins Start a project