title: Connection is not defined in cordova network information plugin
body: <p>I have followed this article:</p>
  
  <p><a href="http://www.joshmorony.com/monitoring-online-and-offline-states-in-an-ionic-application/" rel="nofollow noreferrer">to get network information of the device</a> in ionic app for android.</p>
  
  <p>It works fine on browser but when I install the compiled apk in android phone, it gives an error that says <code>Reference error : Connection is not defined.</code> at  line where I use <code>$cordovaNetwork.isOnline();</code> </p>
  
  <p>I have been banging my head around and have done my due research and tried uninstalling and installing it in the order suggested but no help.</p>
  
  <p>Help me fix this issue. This problem is probably not an issue with code and may be need some clever fix to get it working.</p>
  
  <p>This same issue is being discussed <a href="https://stackoverflow.com/questions/17767933/cordova-3-0-android-connection-is-not-defined">here</a> but I have not really understood where is that given piece of code coming from.</p>
  
  <p><strong>index.html :</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html ng-app="starter" &gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"&gt;
      &lt;meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"&gt;
  
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="lib/ionic/css/ionic.css" rel="stylesheet"&gt;
    &lt;!--   &lt;link href="lib/ionic/css/angular-datepicker.min.css" rel="stylesheet"&gt; --&gt;
      &lt;link href="css/style.css" rel="stylesheet"&gt;
  
      &lt;!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
      &lt;link href="css/ionic.app.css" rel="stylesheet"&gt;
      --&gt;
      &lt;!-- angular date picker css--&gt;
      &lt;link href="lib/datePicker/css/angular-pickadate.css" rel="stylesheet"&gt;
  
      &lt;script src="lib/ionic/js/ionic.bundle.js"&gt;&lt;/script&gt;
      &lt;script src="lib/ionic/js/highcharts-ng.js"&gt;&lt;/script&gt;
      &lt;script src="lib/ionic/js/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="lib/ionic/js/highcharts.js"&gt;&lt;/script&gt;
       &lt;script src="lib/ionic/js/ngStorage.min.js"&gt;&lt;/script&gt;
      &lt;script src="lib/ngCordova/dist/ng-cordova.min.js"&gt;&lt;/script&gt;
  
  
  
      &lt;!-- cordova script (this will be a 404 during development) --&gt;
      &lt;script src="cordova.js"&gt;&lt;/script&gt;
      &lt;!-- your app's js --&gt;
      &lt;script src="js/app.js"&gt;&lt;/script&gt;
         &lt;script src="js/controllers.js"&gt;&lt;/script&gt;
  
  
  
  
  
    &lt;/head&gt;
    &lt;body ng-controller="LoginCtrl"&gt;
  
       &lt;ion-nav-bar class="mob-bar-balanced"&gt;
       &lt;!--  &lt;ion-nav-back-button&gt;
        &lt;/ion-nav-back-button&gt; --&gt;
      &lt;/ion-nav-bar&gt;
      &lt;ion-nav-view&gt;&lt;/ion-nav-view&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>app.js:</strong></p>
  
  <pre><code>app.factory('ConnectivityMonitor', ['$rootScope', '$cordovaNetwork', function($rootScope, $cordovaNetwork){
    return {
      isOnline: function(){
        if(ionic.Platform.isWebView()){
         $rootScope.online = $cordovaNetwork.isOnline();
          return $cordovaNetwork.isOnline();    
        } else {
          $rootScope.online = navigator.onLine;
          return navigator.onLine;
        }
      },
      isOffline: function(){
        if(ionic.Platform.isWebView()){
          $rootScope.online = $cordovaNetwork.isOnline();   
          return !$cordovaNetwork.isOnline();    
        } else {
          $rootScope.online = navigator.onLine;
          return !navigator.onLine;
        }
      },
      startWatching: function(){
          if(ionic.Platform.isWebView()){
  
            $rootScope.$on('$cordovaNetwork:online', function(event, networkState){
              $rootScope.online =true;
              console.log("went online");
            });
  
            $rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
               $rootScope.online =false;
              console.log("went offline");
            });
  
          }
          else {
  
            window.addEventListener("online", function(e) {
              $rootScope.online =true;
              console.log("went online");
            }, false);    
  
            window.addEventListener("offline", function(e) {
              $rootScope.online =false;
              console.log("went offline");
            }, false);  
          }       
      }
    }
  }]);
  
  .config(function($stateProvider,$urlRouterProvider){
    $stateProvider
    .state('Login',{
      url:'/login',
      onEnter:["$state","$localStorage", '$rootScope' , '$ionicViewSwitcher',function($state,$localStorage, $rootScope, $ionicViewSwitcher){
          if((typeof($localStorage.userInfo)!== 'undefined') &amp;&amp; (Object.keys($localStorage.userInfo).length !== 0)) {
                         $ionicViewSwitcher.nextTransition('none');
                         $state.go("Deployment");
  
          }
      }],
      templateUrl:'templates/login.html',
      controller:'LoginCtrl',
      resolve: {
              online: function(ConnectivityMonitor){
                  return ConnectivityMonitor.isOnline();
          }
        }
    })
  </code></pre>