Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Displaying network connection status


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.

How to do it...

In this recipe, we will build an application to constantly check the network connection status of our device:

  1. Firstly, create a new PhoneGap project named networkinfo by running the following command:

    phonegap create networkinfo com.myapp.networkinfo networkinfo
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. We will use the network info plugin as follows:

    cordova plugin add org.apache.cordova.network-information
    
  4. Open www/index.html and let's clean up unnecessary elements. We'll also be manipulating the DOM elements, so include a reference to the xui.js file within the head tag.

  5. We will also set the deviceready...