index.html
<script>
function onDeviceReady() {
alert("onDeviceReady");
var options = {frequency: 500};
watchId = navigator.accelerometer.watchAcceleration(onSuccess, onFailure, options);
}
document.addEventListener("deviceready", onDeviceReady, false);
</script>
Phonegap 3.3.3 device ready handler is not being called.
Make sure you have included the phonegap.js (or cordova.js) script in your html. Otherwise your code is fine. Try commenting everything else except the alert in onDeviceReady() in case the issue still persists.
Try posting your index.html with the question if there are still issues.
It is a best practice to set your event listener in a function after the document finishes loading. Try something like this:
<body onload="onLoad()">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
or with jquery:
$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With