我已尝试过我的设备没有静音但振动插件似乎无法正常工作:
(function () {
"use strict";
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
document.getElementById("vibrate").addEventListener("click", vibrate);
document.getElementById("vibrationPattern").addEventListener("click", vibratePattern);
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
var parentElement = document.getElementById('deviceready');
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
};
function vibrate()
{
var time = 3000;
navigator.vibrate(time);
alert('vibrate(v1) ');
}
function vibratePattern()
{
var pattern = [1000, 1000, 1000, 1000, 1000];
navigator.vibrate(pattern);
alert('Pattern');
}
})();
/////////////////////////////////////////////// ///////////////////////////////// HTML /////////////
<button id="vibrate">VIBRATION</button>
<button id="vibratePattern">PATTERN</button>