Alex Rivera | Logout

How do I disable the Internet connection in Android Emulator?

Asked 2011-12-14T05:21:47.863
73

I am trying to check Internet connectivity on Android using the following method. I have a Wi-Fi 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 {
        // No conection
        return false;
    }
}

I disconnect my PC from the Internet and then try to run the above method. Still it always returns true!? Why?

Edit
Report

1 Answer

86

From Eclipse

To disable the Internet connection, go to Eclipse and do

menu Window -> Show view -> Other -> Android -> Devices

Now select your running emulator and again go to:

menu Window -> Show View -> Other -> Android -> Emulator Control

Now in that... set Data to Unregister from Home.

From Device and Emulator

On the device or in the emulator, go to:

Setting -> Wireless & networks -> Airplane Mode -> OK
answered 2011-12-14T05:33:54.437

Your Answer