When working on a mobile app it's important to know the status of the Internet connection. Using the PhoneGap APIs, you can handle this aspect easily; in fact there are two specific events and an object that allows you to get all the possible information. Once the deviceready
event has been fired you can register a listener for the online
event and another one for the offline
event.
document.addEventListener("online", onDeviceOnline);document.addEventListener("offline", onDeviceOffline);
In the onDeviceOnline
handler, you can easily access the connection object stored in the navigator.connection
property and access the device's cellular and Wi-Fi connection information using the type
property. The possible values stored in the type
property are:
Connection.UNKNOWN
Connection.ETHERNET
Connection.WIFI
Connection.CELL_2G
Connection.CELL_3G
Connection.CELL_4G
Connection.NONE
In order to allow the app to access the connection.type
information, you have to add...