I would like to test the behavior of my application when the user is in a no-signal zone or when his phone is in flight mode.
-> How do I put an Android Virtual Device into offline mode (where no connection to the internet is possible) ?
I have tried the following:
Activating flight mode via the AVD settings: surprisingly, this does NOT work (browsing the internet is still possible in flight mode!)
Disabling the network connection on my PC: this obviously works, but is not satisfactory as I need Internet when I am testing my app
1. just click on "About the emulator" -> "Build Number" about 5-7 times. 2. This will open "developers options", go back and click on it and enable "USB debugging" to bring it online.
The way that Android detects emulators is by scanning ports starting at port 5555. The number you see in the adb devices list (in your case 5554) will be one less than the port that adb is finding open. You probably have a process running that is listening on port 5555.
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.
WIFI:
$ adb shell svc wifi enable
$ adb shell svc wifi disable
MOBILE DATA:
$ adb shell svc data enable
$ adb shell svc data disable
I'm seeing all the same problems. DDMS doesn't fully kill it. Neither does F8. And neither does turning on airplane mode inside the emulator. We should all probably star this issue someone logged in 2009.
I found a working solution. Tested on Android 6.0 an 7.0 emulators, but should work on others.
Network down:
adb shell ifconfig eth0 down
Network up:
adb shell ifconfig eth0 up
If you get a "Permission denied" error, restart adb daemon as root:
adb root
and try again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With