Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the Internet connection in Android Emulator?

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?

like image 368
Chandeep Avatar asked Dec 14 '11 05:12

Chandeep


People also ask

How do I temporarily disable Internet on Android?

To turn off the Internet connection on an Android phone:Go to Settings > Wireless Network > <bold>Mobile. Simply uncheck the box next to Data Enabled so that your phone will not connect over the data network.

Do emulators work without Internet?

No. Not at all. Unless you are running an app that needs internet.

How do I enable Internet on Android Emulator?

Go to your Android\Sdk\emulator folder and open command prompt. Type emulator -list-avds to see available emulator names. Type emulator -avd name-of-your-device -netdelay none -netspeed full -dns-server 8.8. 8.8 command and press enter.


1 Answers

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 
like image 80
MKJParekh Avatar answered Sep 18 '22 11:09

MKJParekh