title: How can I receive a notification when the device loses network connectivity in android L (API 21)
body: <p>I'm using this code to be notified when the connection is lost in API 20 and down.</p>
  
  <pre><code>registerReceiver(getConnectivityStateBroadcastReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
  
  private class ConnectivityStateBroadcastReceiver extends BaseBroadcastReceiver {
  
      /**
       * @param userLoggedIn
       * @param context
       * @param intent
       */
      @Override
      protected void onReceive(Boolean userLoggedIn, Context context, Intent intent) {
  
          Bundle extras = intent.getExtras();
          boolean notConnected = extras.getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
  
          // DO something
      }
  }
  </code></pre>
  
  <p>but it's not working in API 21.</p>
  
  <p>How can I fix that? maybe it's got to do with <a href="https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback.html" rel="noreferrer">ConnectivityManager.NetworkCallbak</a> but I didn't find any example to how to use it. Thanks.</p>