i am trying to check internet connection in my android app
public static boolean isConnectingToInternet(Context _context) {
ConnectivityManager connectivity = (ConnectivityManager) _context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
Log.d("Network",
"NETWORKnAME: " + info[i].getTypeName());
return true;
}
}
return false;
}
but problem is that when i try to check internet connection in emulator by turning off host PC internet connection still this function returning true that is internet available while i have turn off internet connection from host PC
ConnectivityManager
class help in determining whether connected with the network not about the internet connectivity
my question is how to check internet connection is not available ?