Connection

The connection object, exposed via navigator.connection, provides information about the device’s cellular and wifi connection.

Properties

  • connection.type

Constants

  • Connection.UNKNOWN
  • Connection.ETHERNET
  • Connection.WIFI
  • Connection.CELL_2G
  • Connection.CELL_3G
  • Connection.CELL_4G
  • Connection.CELL
  • Connection.NONE

connection.type

This property offers a fast way to determine the device’s network connection state, and type of connection.

Quick Example

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

Source Documentation:

http://plugins.cordova.io/#/package/org.apache.cordova.network-information

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *