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.
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.
Share Improve this question asked Jan 3, 2014 at 19:20 user812954user812954 4,4013 gold badges21 silver badges18 bronze badges 2- 1 Looks good to me. When you say Phonegap 3.3.3, do you mean Cordova 3.3.0 or are you using an edge version. I assume you are trying this on the device/simulator and not through the web browser. deviceready, will not fire in a browser. – Dustin Simpson Commented Jan 3, 2014 at 20:50
- oops, 3.3.3 was a typo, i was using Cordova 3.3.0 – user812954 Commented Jan 8, 2014 at 22:28
3 Answers
Reset to default 4Make sure you have included the phonegap.js (or cordova.js) script in your html. Otherwise your code is fine. Try menting 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);
});
remove app.initialize() from the script (that messes up the event handler)