Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Markus_W_1
Beginner
79 Views

Navigator.connection not available

Jump to solution

Hello,

I'm building an app with Cordova 5.4.1 and I got the cordova-plugin-network-information; but in the emulator or on the device (iOS and Android) the navigator.connection is undefined.

What am I doing wrong?

Thanks for help!

Tags (2)
0 Kudos

Accepted Solutions
Markus_W_1
Beginner
79 Views

Well, I forgot to include the cordova.js! Thanks you.

View solution in original post

0 Kudos
3 Replies
Amrita_C_Intel
Employee
79 Views

Once you added Cordova Network plugin, you can detect network details as:

function checkConnection() {
    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('Connection type: ' + states[networkState]);
}

checkConnection();
0 Kudos
Amrita_C_Intel
Employee
79 Views

Which XDK version are you using?

0 Kudos
Markus_W_1
Beginner
80 Views

Well, I forgot to include the cordova.js! Thanks you.

View solution in original post

0 Kudos