Possible Duplicate:
Checking internet connection on android
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.
public boolean isDeviceConnectedToInternet() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
User permissions are set:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I turned off my wifi and running the app , I got true in Log cat.
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.