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

Posted by medicdave on Stack Overflow See other posts from Stack Overflow or by medicdave
Published on 2010-06-09T03:15:50Z Indexed on 2010/06/09 3:22 UTC
Read the original article Hit count: 2047

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about unit-testing