Software Archive
Read-only legacy content
17061 Discussions

Navigator.connection not available

Markus_W_1
Beginner
493 Views

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!

0 Kudos
1 Solution
Markus_W_1
Beginner
493 Views

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

View solution in original post

0 Kudos
3 Replies
Amrita_C_Intel
Employee
493 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
493 Views

Which XDK version are you using?

0 Kudos
Markus_W_1
Beginner
494 Views

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

0 Kudos
Reply