my first time experimenting with Apache Cordova 3.0.
downloaded lib, unziped cordova-android and cordova-js and created a project:
./create ~/Documents/andriod-projects/HelloWorld com.x.HelloWorld HelloWorld
- OK
res/xml/config.xml
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
on index.js device ready:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
var networkState = navigator.connection.type;
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("Network: "+states[networkState]);
}
when I emulate the project on my andriod I got in LogCat Error:Connection is not defined
:
what I am missing? I have to attach a .js in order to Connection be declared?
I had the same exact problem, but was able to fix it. Running the below commands as per the Phonegap Connection docs doesn't seem to work:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
$ cordova plugin rm org.apache.cordova.core.network-information
Instead, I had to use:
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
Once I did that, it worked.
I resolved by:
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
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