Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I refresh the Android emulator network connection after the host switches network?

I'm running an Android API 23 x86 emulator from SDK on my MacBook. When I switch WiFi network the Android emulator loses all connections to the internet or intranet.

Every time I switch my WiFi network I need to reboot my emulator to reset the network of the virtual Android device.

Is there an option to reinitialise the network connection of the emulator without rebooting?

like image 610
Rene Avatar asked Aug 11 '16 08:08

Rene


People also ask

How do I change DNS on Android emulator?

Then run one of the available emulators with the command, “emulator -avd DEVICE_NAME”, followed by the argument “-dns-server 8.8. 8.8”. This will launch the emulator and overwrite the default DNS server address, replacing it with the address of the primary DNS server for Google DNS.


1 Answers

You can set on/off AirPlane mode from the command line:

adb shell settings put global airplane_mode_on 1 && adb shell settings put global airplane_mode_on 0

Note - also try this from ADB shell (Depends on your pc tcp drivers):

settings put global airplane_mode_on 1 && am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true && settings put global airplane_mode_on 0 && am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false

By doing so you re-initialize TelephonyManager and refresh the device modem drivers.

like image 178
Nir Duan Avatar answered Nov 15 '22 13:11

Nir Duan