Over a million developers have joined DZone.

Cordova (Formerly PhoneGap) Network Type and Status in Windows Phone

DZone's Guide to

Cordova (Formerly PhoneGap) Network Type and Status in Windows Phone

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

In this article I will discuss how to detect Network availability and Network type in Windows Phone using PhoneGap.

If this is your first time use of Cordova or PhoneGap, I would recommend to read Getting Started with Cordova or PhoneGap in Windows Phone

Let's write some code to create contact:

Step 1: Open index.html under www folder and put below code.

<!DOCTYPE html>
      <title>Getting Started Sample</title>
      <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
      <script type="text/javascript" charset="utf-8">
         var init = function init() {
            // Wait for Cordova to load
            document.addEventListener("deviceready", onDeviceReady, false);
            // Cordova is ready
            function onDeviceReady() {

         window.onload = init;

Step 2: Now modify onDeviceReady method like below which will notify if network is available or not and if available it will notify network type.

There are two event listener in onDeviceReady method, online and offline. online event triggers when device is connected to internet otherwise offline event triggers.

function onDeviceReady() {
   if (navigator.network.connection.type != Connection.NONE) {
   else {
      alert("You are not connected");
   document.addEventListener("online", onOnline, false);
   document.addEventListener("offline", onOffline, false);

Step 3: Now add NetworkType method which will notify the connection type the device is connected to.

function NetworkType() {
   switch (navigator.network.connection.type) {
      case Connection.UNKNOWN:
         alert("Connection type is not known");
      case Connection.ETHERNET:
         alert("Connection type is Ethernet");
      case Connection.WIFI:
         alert("Connection type is WiFi");
      case Connection.CELL_2G:
         alert("Connection type is 2G");
      case Connection.CELL_3G:
         alert("Connection type is 3G");
      case Connection.CELL_4G:
         alert("Connection type is 4G");
      case Connection.NONE:
         alert('No Network Connection');

Step 4: Now add onOnline and onOffline method where we can right certain action which can be taken based on the application connected to internet or not


function onOnline() {
   //Perform action in case of online

function onOffline() {
   //Perform action in case of offline

Step 5: Now run the application and you will get screen like below, in my case I am connected to WiFi.

Cordova PhoneGap - Network Status Windows Phone

This ends the article of detecting network status and type using Cordova or PhoneGap in Windows Phone.


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of Sumit Dutta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}