35

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?

1
  • so how could u deal with this? have u solved it out?
    – gumuruh
    Commented Aug 20, 2018 at 23:51

6 Answers 6

20

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.

9

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.

2
  • 2
    Correct, but only in the licensed version atm. Commented Jan 5, 2016 at 16:56
  • 1
    2017 update, it's now available in the API 25 emulator when you disable hardware acceleration -
    – IT-Dan
    Commented Oct 22, 2017 at 8:39
5

Android emulator wifi

Starting from revision 26.1.3, the Android emulator now supports connecting to WiFi on a Nougat image (API 25).

Added support for Wi-Fi in some system images (currently only API level 25). An access point called "AndroidWifi" is available and Android automatically connects to it.

Source: https://developer.android.com/studio/releases/emulator.html#26-1-3

You can check the version of your emulator by going into emulator settings (three dots) > Help > About. Also note that if an AVD was created before version 26.1.3 was released, you will have to recreate your AVD. I read somewhere that wiping data might also work, but I did not try that.

1
  • 1
    I needed to disable hardware acceleration for it to be available. At time of writing set Emulated Performance Graphics to Software - GLES 2.0.
    – IT-Dan
    Commented Oct 22, 2017 at 8:37
4

In theory, linux (the kernel underlying android) has mac80211_hwsim driver, which simulates WiFi. It can be used to set up several WiFi devices (an acces point, and another WiFi device, and so on), which would make up a WiFi network.

It's useful for testing WiFi programs under linux. Possibly, even under user-mode linux or other isolated virtual "boxes" with linux.

In theory, this driver could be used for tests in the android systems where you don't have a real WiFi device (or don't want to use it), and also in some kind of android emulators. Perhaps, one can manage to use this driver in android-x86, or--for testing--in android-x86 run in VirtualBox.

4

If you don't have a real device, I think the best way is installing android-x86 or use it on live usb. There is no diffrences between android and android-x86.

And android-x86 support wi-fi. so you can install your app, and run it.

2
  • alright... but does it work as it is ? I mean simulating wifi from that emulator (virtualbox) ? :D
    – gumuruh
    Commented May 20, 2014 at 15:05
  • As of today, it doesn't. Commented Jan 5, 2016 at 16:54
2

Probably no substitute for testing on a real device, but if you're looking for a good enough test case in the emulator give Fake Wifi Connection a try:

It makes apps think they're on wifi no matter what the underlying connection is.

disclaimer: I wrote this stuff.
It works by intercepting ConnectivityManager / WifiManager calls (uses Xposed). I've tried to cover most of them so it does a pretty good job, nevertheless it's always possible some is missing (if you find something let me know).

Not the answer you're looking for? Browse other questions tagged or ask your own question.