Internet connection in android emulator always displays connected state

Posted by ganesh on Stack Overflow See other posts from Stack Overflow or by ganesh
Published on 2010-04-08T12:09:27Z Indexed on 2010/04/08 12:13 UTC
Read the original article Hit count: 407

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

© Stack Overflow or respective owner

Related posts about android

Related posts about internet-connection