title: Android: Internet connectivity change listener
body: <p>I already have this code which listens to connectivity change -</p>
  
  <pre><code>public class NetworkStateReceiver extends BroadcastReceiver
  {
    public void onReceive(Context context, Intent intent)
    {
      Log.d("app","Network connectivity change");
  
      if(intent.getExtras() != null)
      {
        NetworkInfo ni = (NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
        if(ni != null &amp;&amp; ni.getState() == NetworkInfo.State.CONNECTED)
        {
          Log.i("app", "Network " + ni.getTypeName() + " connected");
        }
      }
  
      if(intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE))
      {
        Log.d("app", "There's no network connectivity");
      }
    }
  }
  </code></pre>
  
  <p>And I check Internet connectivity using this code - <a href="https://stackoverflow.com/questions/6493517/detect-if-android-device-has-internet-connection/6493572#6493572">Internet Check</a></p>
  
  <p>But the problem is that if network suddenly loses internet connection without any connectivity change, this code is useless. Is there any way to create <strong>Broadcast Receiver</strong> listener for Internet connectivity change? I have a web app and sudden Internet connectivity changes can cause problems.</p>