In my application, which I test on emulator, I use the following code to check the network connection (WIFI):
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
This method returns always true
, even if I disable the wireless connection of my computer...
Is this caused by the emulator or is it something else?
If this is not the right way to check network connection, how can I do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…