[ACCEPTED]-Android: Simulate WiFi in the emulator?-device-emulation

Accepted answer
Score: 20

Currently, while you can use your computer's 9 Internet connection in the emulator, it's 8 not reliable to use it for simulating Wi-Fi. The 7 WifiManager gets confused when you switch/want to test 6 your connectivity state.

Even in Android 5 1.5, there were some problems with it (Issue 2571 - android), and 4 while you can use your Internet for simulating 3 HTTP connections and downloading data, finer 2 control over Wi-Fi connectivity should better 1 be done with a device.

Score: 9

Since this seems to be a popular question, I'll 5 go ahead and add an updated answer. The 4 SDK still doesn't support WiFi emulation, but 3 Genymotion does WiFi by default, so you can use that 2 to develop/test apps with specific WiFi 1 functionality.

Score: 5

Android emulator wifi

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

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

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

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

Score: 4

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

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

Score: 4

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

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

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

Score: 2

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

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

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

More Related questions