Android:While running in my Android device it's working. But I can't figure > out why the same thing is not happening in my emulator
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4086159/checking-internet-connection-on-android">Checking internet connection on android</a>  </p>
</blockquote>



<p>In my application I want to check internet connection. If the device is not connected to internet I want to close my app. So I use this method for checking the internet connection. </p>

<pre><code>public boolean isDeviceConnectedToInternet() {
        ConnectivityManager cm =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null &amp;&amp; netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }
</code></pre>

<p>User permissions are set:</p>

<pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
</code></pre>

<p>I turned off my wifi and running the app , I got true in Log cat.</p>

<blockquote>
  <p>While running in my Android device it's working. But I can't figure
  out why the same thing is not happening in my emulator.</p>
</blockquote>
