I'm using the following code to detect screen size, then if it's large, to do a connection check to let the user know, if the connection is broken, that they won't be able to download wallpaper.
This script works fine with the iPad. Testing it with Android (Nexus 7, Android V4.3, sdkv16) the screen merely goes dark after the splashcreen. None of the alerts fire.
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no" name="viewport">
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("onDeviceReady");
if (screen.width > 640) {
checkConnection();
function checkConnection() {
alert("checkConnection");
if (!navigator.onLine) {
navigator.notification.alert('No Internet connection available. You cannot download wallpaper at this time.',
alertDismissed, // callback
'No Connection', // title
'Done' // buttonName
);
}
}
else {
window.location.href = "iphone/index.html";
}
}
function alertDismissed() {
window.location = "ipad/index.html";
}
</script>
<style type="text/css">
body { background-color: #333333; }
</style>
</head>
<body>
</body>
</html>
Plugin installed:
org.apache.cordova.network-information 0.2.9 "Network Information"
AndroidManifest:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
config.xml:
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
My development environment:
Mac OS X 10.9.3 on latest Mac Mini
Cordova CLI 3.5.0 (cordova, not phonegap)
for Android 4.3 targetSdk v17
ADT v22.0.1 with Eclipse platform (not using Eclipse at this time)
Testing in device: Nexus 7 2012 with 4.3 Jelly Bean ("cordova build")
Not for PG Build; using JQuery after the first page
Not single-page architecture