PhoneGap on Android deviceready not working!
Solution 1
Make sure the name of the cordova script is spelled correctly: it may read
<script type="text/javascript" charset="utf-8" src="cordova-1.x.x.js"></script>
where it should read:
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
Solution 2
Make sure that "<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />"
is present in AndroidManifest.xml.
Solution 3
I could get rid of this issue when I found out, that the cordova version numbers of my cordova.js and the cordova.jar file didn't match.
Getting both from the same cordova version fixed it for me. That was a time consuming and stupid mistake on muy side.
Mr. D
Updated on June 05, 2022Comments
-
Mr. D almost 2 years
I'm working on a mobile application using phoneGap. I'm showing deviceInfo and and it's not working on Android emulator! but works on BlackBerry emulator. I`m using Dreamweaver cs 5.5. Any solution to this issue?
Here is my code:
// invoked when device is ready function deviceInfo() { document.getElementById('window.device.platform').innerHTML = 'window.device.platform = ' + window.device.platform; document.getElementById('window.device.version').innerHTML = 'window.device.version = ' + window.device.version; document.getElementById('window.device.uuid').innerHTML = 'window.device.uuid = ' + window.device.uuid; document.getElementById('window.device.phonegap').innerHTML = 'window.device.phonegap = ' + window.device.phonegap; navigator.network.isReachable("phonegap.com", function(reachability) { var states = {}; states[NetworkStatus.NOT_REACHABLE] = 'No network connection'; states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection'; states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection'; document.getElementById('networkStatus').innerHTML = 'isReachable = ' + states[reachability]; }, { isIpAddress: false }); } // invoked when application is resumed (brought to foregroud) function doResume() { console.log('doResume()'); } // invoked when application is paused (sent to background) function doPause() { console.log('doPause()'); } // register PhoneGap event listeners when DOM content loaded function init() { console.log('init()'); document.addEventListener("deviceready", deviceInfo, true); document.addEventListener("resume", doResume, false); document.addEventListener("pause", doPause, false); } function unload() { console.log('unload()'); } function fail(error) { navigator.notification.alert(error, null, "Error"); }
On my HTML:
<body onload="init()" onunload="unload()">