Network checking in android
<p>I want to check the network connectivity in android application.so i inserted the following code</p>

<pre><code>public boolean isNetworkAvailable() {
     Context context = getApplicationContext();
     ConnectivityManager connectivity = (ConnectivityManager) 
        context.getSystemService(Context.CONNECTIVITY_SERVICE);

      NetworkInfo[] info = connectivity.getAllNetworkInfo();
      if (info != null)
      {
       for (int i = 0; i &lt; info.length; i++) 
       {
        if (info[i].getState() == NetworkInfo.State.CONNECTED) 
        {
         return true;
        }
       }
      }

     return false;
    }
</code></pre>

<p>when i removed network cable in my computer the program crashed.but when i disable Airplane Mode in Emulator,it correctly shows "NETWORK NOT AVAILABLE".
How to we actually check?</p>
