I would like to check from my app whether the device has WiFi connectivity, but in order to do that, I must first find a way to get "WiFi" in the emulator. Just going to Settings -> Wireless controls -> Wifi says Unable to start Wi-Fi, while logcat
says:
E/WifiService( 566): Failed to load Wi-Fi driver. D/SettingsWifiEnabler( 695): Received wifi state changed from Unknown to Enabling D/SettingsWifiEnabler( 695): Received wifi state changed from Enabling to Unknown
How can I simulate WiFi connectivity in the emulator?
The Android UI is pretty simple, if your connected to Wifi it shows in the notification bar, it can also show your cellular connectivity at the same time depending on what has happened. All you have shown is that you can use the emulator on a wifi connected host machine, which is not what this question was asking.
If your emulator must access the internet through a proxy server, you can configure a custom HTTP proxy from the emulator's Extended controls screen. With the emulator open, click More , and then click Settings and Proxy. From here, you can define your own HTTP proxy settings.
Android: Using real 2G/3G No need for developer settings on an Android device: go to Parameters > Wi-Fi and Internet > Mobile network > Preferred network type. You can then select if you want to enable 4G, 3G or only 2G.
The problem seems to be that the emulator can't find the DNS my computer is currently using, and the temporary workaround is to start the emulator from the command line and specify the DNS server. Whatever problem occurred back then must have reappeared in the latest version of Android Studio.
Currently, while you can use your computer's Internet connection in the emulator, it's not reliable to use it for simulating Wi-Fi. The WifiManager
gets confused when you switch/want to test your connectivity state.
Even in Android 1.5, there were some problems with it (Issue 2571 - android), and while you can use your Internet for simulating HTTP connections and downloading data, finer control over Wi-Fi connectivity should better be done with a device.
Since this seems to be a popular question, I'll go ahead and add an updated answer. The SDK still doesn't support WiFi emulation, but Genymotion does WiFi by default, so you can use that to develop/test apps with specific WiFi functionality.
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