Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova 3.0: Android: Connection is not defined

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:

enter image description here

what I am missing? I have to attach a .js in order to Connection be declared?

like image 802
panchicore Avatar asked Jul 21 '13 00:07

panchicore


2 Answers

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.

like image 113
Julian Avatar answered Oct 19 '22 22:10

Julian


I resolved by:

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
like image 37
Regis Avatar answered Oct 19 '22 21:10

Regis