Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Simulate WiFi in the emulator?

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?

like image 261
Felix Avatar asked Oct 13 '09 22:10

Felix


People also ask

Can you use Wi-Fi on an 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.

How do I enable Internet on emulator?

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.

How do I simulate no network?

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.

Why is Internet not working on emulator?

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.


2 Answers

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.

like image 67
Dimitar Dimitrov Avatar answered Sep 24 '22 01:09

Dimitar Dimitrov


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.

like image 36
Felix Avatar answered Sep 21 '22 01:09

Felix