Internet connection in android emulator always displays connected state
- by ganesh
hi
I tried in many ways to check Internet connection in my android emulator
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info= conMgr.getActiveNetworkInfo();
if(info != null || info.isConnected()) {
Log.v("NetworkInfo","Connected State");
}
else{
Log.v("NetworkInfo","Not Connected state");
Log.v("Reason",info.getReason());
}
even if i disable Internet connection in my system ,my code seems to display Connected state
so i guessed this may work
if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED
|| conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ) {
Log.v("Congr","Connection Present");
}
else if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED
|| conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED) {
Log.v("conMgr"," No Connection");
}
but the above code also displays "Connection Present" even when i disconnect Internet cables.
.Please help to find a correct way to do this .I have ACCESS_NETWORK_STATE and INTERNET permission in my manifest file