Book Image

PhoneGap for Enterprise

By : Kerri Shotts
Book Image

PhoneGap for Enterprise

By: Kerri Shotts

Overview of this book

Table of Contents (16 chapters)
PhoneGap for Enterprise
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the current network type


Anytime after the deviceready event fires, you can query the plugin for the status of the current network connection by querying navigator.connection.type:

var networkType = navigator.connection.type;
switch (networkType) {
  case Connection.UNKNOWN:
  console.log ("Unknown connection."); break;
  case Connection.ETHERNET:
  console.log ("Ethernet connection."); break;
  case Connection.WIFI:
  console.log ("Wi-Fi connection."); break;
  case Connection.CELL_2G:
  console.log ( "Cellular (2G) connection."); break;
  case Connection.CELL_3G:
  console.log ( "Cellular (3G) connection."); break;
  case Connection.CELL_4G:
  console.log ( "Cellular (4G) connection."); break;
  case Connection.CELL:
  console.log ( "Cellular connection."); break;
  case Connection.NONE:
  console.log ( "No network connection."); break;
}

If you executed the preceding code on a typical mobile device, you'd probably either see some variation of the Cellular connection or the Wi-Fi...