Cordova Plugin Vibration
The Cordova Plugin Vibration allows developers to vibrate the device in different patterns and durations. This plugin provides an easy way to integrate vibration functionality into Cordova applications.
Installation
To install the Cordova Plugin Vibration, follow the steps below:
- Open a terminal or command prompt.
- Navigate to your Cordova project’s root directory.
- Run the following command:
cordova plugin add cordova-plugin-vibration
Plugin Usage
To use the Cordova Plugin Vibration in your application, follow the sample code below:
// Vibrate the device for 2 seconds
navigator.vibrate(2000);
The above code snippet will vibrate the device for 2 seconds.
API Reference
Vibration
navigator.vibrate(duration)
The vibrate()
method allows developers to vibrate the device using a specified duration.
Parameters
- duration (optional): The duration of the vibration in milliseconds. Defaults to 1000ms.
Callback
This method does not have a callback function.
Examples
// Vibrate for 1 second
navigator.vibrate(1000);
// Vibrate with default duration
navigator.vibrate();
// Stop vibration
navigator.vibrate(0);
Compatibility
The vibrate()
method is supported on:
- Android
- iOS
- Windows
Conclusion
The Cordova Plugin Vibration simplifies the process of integrating vibration functionality into Cordova applications. By using the provided methods, developers can easily control the device’s vibration settings and create more engaging user experiences.