I am using this code to check for the internet connection:
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
// test for connection
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
but even when I turn off the wifi it still returns true.
Tried both on emulator and device with same result?
What is wrong ?
This simple code works in my case:
Also this one..