Cordova Tutorial
Cordova Useful Resources
Selected Reading
- Cordova - Best Practices
- Cordova - Whitelist
- Cordova - Vibration
- Cordova - Splash Screen
- Cordova - Network Information
- Cordova - Media Capture
- Cordova - Media
- Cordova - InAppBrowser
- Cordova - Globalization
- Cordova - Geolocation
- Cordova - File Transfer
- Cordova - File System
- Cordova - Dialogs
- Cordova - Device Orientation
- Cordova - Accelerometer
- Cordova - Device
- Cordova - Contacts
- Cordova - Camera
- Cordova - Battery Status
- Cordova - Plugman
- Cordova - Back Button
- Cordova - Events
- Cordova - Storage
- Cordova - Config.xml File
- Cordova - First Application
- Cordova - Environment Setup
- Cordova - Overview
- Cordova - Home
Cordova Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Cordova - Vibration
Cordova - Vibration
This plugin is used for connecting to device s vibration functionapty.
Step 1 - Instalpng Vibration Plugin
We can install this plugin in command prompt window by running the following code −
C:UsersusernameDesktopCordovaProject>cordova plugin add cordova-plugin-vibration
Step 2 - Add Buttons
Once the plugin is installed we can add buttons in index.html that will be used later to trigger the vibration.
<button id = "vibration">VIBRATION</button> <button id = "vibrationPattern">PATTERN</button>
Step 3 - Add Event Listeners
Now we are going to add event psteners inside onDeviceReady in index.js.
document.getElementById("vibration").addEventListener("cpck", vibration); document.getElementById("vibrationPattern").addEventListener("cpck", vibrationPattern);
Step 4 - Create Functions
This plugin is very easy to use. We will create two functions.
function vibration() { var time = 3000; navigator.vibrate(time); } function vibrationPattern() { var pattern = [1000, 1000, 1000, 1000]; navigator.vibrate(pattern); }
The first function is taking time parameter. This parameter is used for setting the duration of the vibration. Device will vibrate for three seconds once we press VIBRATION button.
The second function is using pattern parameter. This array will ask device to vibrate for one second, then wait for one second, then repeat the process again.
Advertisements