Your application may require the user to be connected to a network. This may be for partial updates, remote data transfer, or streaming. Using the PhoneGap API and network information plugin, we can easily detect the status or existence of any network connectivity.
In this recipe, we will build an application to constantly check the network connection status of our device:
Firstly, create a new PhoneGap project named
networkinfo
by running the following command:phonegap create networkinfo com.myapp.networkinfo networkinfo
Add the devices platform. You can choose to use Android, iOS, or both:
cordova platform add ios cordova platform add android
We will use the network info plugin as follows:
cordova plugin add org.apache.cordova.network-information
Open
www/index.html
and let's clean up unnecessary elements. We'll also be manipulating the DOM elements, so include a reference to thexui.js
file within thehead
tag.We will also set the
deviceready...