I have tried following this guide on Cordova docs, but it doesn't seem to work.
Here is my code:
I have added <plugin name="NetworkStatus" value="CDVConnection" />
to config.xml
.
and this script to my index.html
:
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
alert("1"); // runs this alert
checkConnection();
}
function checkConnection() {
var networkState = Connection.CELL;
alert("2"); // doesn't run this
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
</script>
var networkState = Connection.CELL;
seems to cause the problem as it doesn't run the following alert, I have also tried navigator.connection.type
but the same thing happened.
When I run the app in Chrome the console outputs the following error:
Uncaught ReferenceError: Connection is not defined
Anybody know how to solve this problem?
Cheers