Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable/enable network, switch to Wifi in Android emulator?

I'm working on a Push Notifications library for Android (http://deaconproject.org/) that needs to take action if network connectivity is interrupted or changed - namely, it needs to re-initiate a server connection or pause its operation until network connectivity is available. This seems to work fine using and Android BroadcastReceiver for "android.net.ConnectivityManager.CONNECTIVITY_ACTION".

My problem is in testing the library - I would like to automatically test the library's response to a broken network connection, or a transition from 3G to WiFi, under various configuration conditions. The problem is, I don't want to sit with the emulator and hit F8 all day.

Is there a way to programmatically manipulate network connections on Android from within a jUnit test without resorting to toggling Airplane Mode? I've already tried issuing commands to the emulator via the console, manipulating the GSM mode, etc, but while the phone state changes on the display, the Internet connection remains up.

like image 799
mtbkrdave Avatar asked Jun 09 '10 03:06

mtbkrdave


People also ask

How do I turn off WiFi on my emulator?

You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn't have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.

How do I disable emulators on Android?

You can uninstall from Android Studio by going to Tools in the menu and selecting SDK Manager, and then the SDK Tools tab and unchecking the box for Android Emulator and then clicking Apply.

How do I turn off bluestacks WiFi?

There is no any feature provided by Bluestacks to manually turn off the wifi when not in use but using " BS Net Blocker" you can turning on or off manually according to your needs. This program might affect your files too as it is not secure.

What is the method used to enable the WiFi in Android Studio?

setWifiEnabled(false); So you can enable or disable WiFi using WifiManger class. You need to add extra permissions in AndroidManifest. xml to enable or disable Wifi.


2 Answers

I've found the Android Dev Tools app really helpful.

It allows you to manipulate important system settings like network connectivity. It even allows you to set an interval in which it toggles wifi on and off automatically thus allowing you to test you network related broadcast receivers.

If you'd like to install the Dev Tools application on a real development device, you can copy the application from your emulator and then install it on your device using ADB. To copy the application from a running emulator, execute:

adb -e pull /system/app/Development.apk ./Development.apk 

This copies the .apk file into the current directory. Then install it on your connected device with:

adb -d install Development.apk 

enter image description here

like image 22
Sander Versluys Avatar answered Sep 18 '22 22:09

Sander Versluys


Right click on project in the "Project Explorer" panel, chose "Run As" then "Run Configurations".

On the left side of the modally shown window chose "Android Application" and on the right side of the same window, chose tab "Target".

At the bottom of the window, in the "Emulator Launch Parameters" section you have plethora of options regarding internet connectivity.

I hope this helped.

Igor

like image 91
Igor Avatar answered Sep 22 '22 22:09

Igor