Need Help in Checking Internet Connection in Android?
<p>Hai Friends,
           I want to display a toast message to the user, when there is poor or no internet connection, so i have written the following code in my activity.</p>

<blockquote>
  <p>ConnectivityManager conMgr = ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);</p>

<pre><code>  if (
</code></pre>
  
  <p>conMgr.getNetworkInfo(0).getState() ==
  NetworkInfo.State.CONNECTED 
            ||  conMgr.getNetworkInfo(1).getState() ==
  NetworkInfo.State.CONNECTING  ) {</p>

<pre><code>      //notify user you are online

  }       else if (
</code></pre>
  
  <p>conMgr.getNetworkInfo(0).getState() ==
  NetworkInfo.State.DISCONNECTED 
            ||  conMgr.getNetworkInfo(1).getState() ==
  NetworkInfo.State.DISCONNECTED) {
            //notify user you are not online</p>

<pre><code>      Toast.makeText(getBaseContext(),"Please
</code></pre>
  
  <p>Check Your Internet Connection and Try
  Again",Toast.LENGTH_SHORT).show();</p>

<pre><code>  }
</code></pre>
</blockquote>

<p>The error message in Log is </p>

<pre><code>10-25 15:52:03.412: ERROR/AndroidRuntime(19084): Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10031 nor current process has android.permission.ACCESS_NETWORK_STATE.
10-25 15:52:03.412: ERROR/AndroidRuntime(19084):     at android.os.Parcel.readException(Parcel.java:1218)
10-25 15:52:03.412: ERROR/AndroidRuntime(19084):     at android.os.Parcel.readException(Parcel.java:1206)
10-25 15:52:03.412: ERROR/AndroidRuntime(19084):     at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:266)
10-25 15:52:03.412: ERROR/AndroidRuntime(19084):     at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:153)
</code></pre>
