title: cordova online/offline events not firing in android
body: <p>I want to listen, when my device goes offline/online in my Cordova app, but I am unable to achieve it. I could see other <a href="https://stackoverflow.com/questions/18160866/phonegap-events-online-offline-not-working">questions</a> here in SO,  with the same topic, but none are resolved. I tried as said in the Cordova <a href="https://cordova.apache.org/docs/en/2.9.0/cordova_events_events.md.html#online" rel="nofollow noreferrer">documentation</a>.</p>
  
  <p>This is what I did. I created a new Cordova android project using CLI (btw I'm using Cordova 3.4), then added  'org.apache.cordova.network-information' plugin as below.</p>
  
  <pre><code>cordova plugin add org.apache.cordova.network-information
  </code></pre>
  
  <p>My config file has entry as below.</p>
  
  <pre><code>&lt;feature name="NetworkStatus"&gt;
      &lt;param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" /&gt;
  &lt;/feature&gt;
  </code></pre>
  
  <p>And my AndroidManifest file has the below entries.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>
  
  <p>My JS code is below.</p>
  
  <pre><code>initialize: function() {
      //alert('initialise');
      this.bindEvents();
  },
  // Bind Event Listeners
  bindEvents: function() {
      document.addEventListener('deviceready', this.onDeviceReady, false);
  },
  // deviceready Event Handler
  onDeviceReady: function() {
      alert('device ready');
      document.addEventListener('online', this.onDeviceOnline, false);
      document.addEventListener('offline', this.onDeviceOffline, false);
  },
  
  onDeviceOnline: function() {
      alert('onDeviceOnline');
  },
  
  onDeviceOffline: function() {
      alert('onDeviceOffline');
  }
  </code></pre>
  
  <p>It always comes to device ready, but never comes to online/offline event handlers when I connect/disconnect my wi-fi (and cellular data as well).</p>
  
  <p>When I call below method it alerts the connection type correctly.So I know my plugin installation was successful. </p>
  
  <pre><code>function checkConnection() {
  alert('checking connection');
  var networkState = navigator.connection.type;
  
  var states = {};
  states[Connection.UNKNOWN]  = 'Unknown connection';
  states[Connection.ETHERNET] = 'Ethernet connection';
  states[Connection.WIFI]     = 'WiFi connection';
  states[Connection.CELL_2G]  = 'Cell 2G connection';
  states[Connection.CELL_3G]  = 'Cell 3G connection';
  states[Connection.CELL_4G]  = 'Cell 4G connection';
  states[Connection.CELL]     = 'Cell generic connection';
  states[Connection.NONE]     = 'No network connection';
  
  alert('Connection type: ' + states[networkState]);
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me on this. I'm stuck on this issue for some time now.</p>
  
  <p>Thanks</p>