Code for vibrate the android mobile using cordova
The following codova plugin is used to control the vibration in android mobile. This can be set the time of vibration and cancel the vibration.
Screen shot:
cordova plugin add cordova-plugin-vibration
Screen shot:
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>Vibration Test</title>
</head>
<body>
<center>
<input type="button" value="Vibrate 3 sec" onclick="vibr3();">
<br>
<input type="button" value="Vibrate 5 sec" onclick="vibr5();">
<br>
<input type="button" value="Vibrate 20 sec" onclick="vibr20();">
<br>
<input type="button" value="Stop & Start" onclick="stepvibr();">
<br>
<input type="button" value="Stop Vibration" onclick="stpvibr();">
<br>
</center>
<script type="text/javascript" src="cordova.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(navigator.vibrate);
}
function vibr3() {
navigator.vibrate(3000); //3second
}
function vibr5() {
navigator.vibrate(5000); //3second
}
function vibr20() {
navigator.vibrate(20000); //20second
}
function stpvibr() {
navigator.vibrate(0); //Stop Vibration
}
function stepvibr() {
// Vibrate for 1 second
// Wait for 1 second
// Vibrate for 3 seconds
// Wait for 1 second
// Vibrate for 5 seconds
navigator.vibrate([1000, 1000, 3000, 1000, 5000]);
}
</script>
</body>
</html>
Nhận xét
Đăng nhận xét