title: Android networkinfo always returns true even if internet is not available
body: <p>This code always returns true. This gets called when a Login button is pressed. I first tried with wifi connected (on emulator). It returned true and then I disconnected wifi and then tried. it still returns true.</p>
  
  <pre><code>public static boolean isNetworkAvailable( Context context) {
  
      ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo networkInfo = cm.getActiveNetworkInfo();
              // if no network is available networkInfo will be null
              // otherwise check if we are connected
              if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
                   State network = networkInfo.getState();
                   Log.d("here", "true");
                   return (network == NetworkInfo.State.CONNECTED || network == NetworkInfo.State.CONNECTING);
  
              }
              Log.d("here1", "false");
              return false;
  }
  </code></pre>