title: android how to get indicate when the internet connection is lost?
body: <p>I'm developing an android application and I want to get a notification when the internet (wifi or packet data connection) connection is lost. On my approach I can get the status of the connection as:</p>
  
  <pre><code>private boolean isNetworkAvailable() {
  ConnectivityManager connectivityManager 
        = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
  return activeNetworkInfo != null &amp;&amp; activeNetworkInfo.isConnected();
  }
  </code></pre>
  
  <p>while having this in the Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  </code></pre>
  
  <p>How could I be notified automatically when the connection is lost?</p>