Javatpoint Logo
Javatpoint Logo

Cordova Plugin Network Information

This plugin is used to provide any information about the cellular and wifi connections of the device. We can use this method to detect the current state of network information. It will respond if any changes occurred. If we talk about the compatibility of this plugin, it is supported in various platforms such as Windows, Android, iOS, Browser. You can easily install this plugin by typing the below command:

A navigator.connection object is responsible for the availability of a connection object after the Cordova deviceready event. In the below code, the type property includes the current network state.

Connection

It is responsible for providing information about the cellular and wifi connection of the device. For doing this, a navigator.connection object is used for providing an availability of the connection object. Until Cordova version 2.3.0, the navigator.network.connection was used to access the Connection object. But after that, its API changed to navigator.connection for matching the W3C specification.

Properties:

connection.type: This type of property determines the current network state and the type of connection.

Example:

Constants:

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

Network related Events

offline:

As the name suggests, when the application goes offline and the device is not connected to internet, the offline event is fired. This means that if your previously connected device disconnects from the network, a user will have no longer access the internet. When connection.type value becomes NONE, this event is fired. After the deviceready event is fired, we should use document.addEventListener for attaching an event listener.

online:

As the name suggests, when the application goes online and the device becomes connected to the internet, this event is fired. This means that when your previously connected device receives network connection for accessing the internet, the online event will be fired. This event is fired when connection.type value changes from NONE to any other value and it depends on the same information as the Connection API. It should be recommended that use the document.addEventListener for attaching an event listener after the deviceready event fired.






Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA