Android: Simulate WiFi in the emulator?

前端 未结 6 1499
礼貌的吻别
礼貌的吻别 2020-11-28 10: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 <

相关标签:
6条回答
  • 2020-11-28 10:51

    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.

    0 讨论(0)
  • 2020-11-28 10:52

    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.

    0 讨论(0)
  • 2020-11-28 10:54

    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.

    0 讨论(0)
  • 2020-11-28 11:01

    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).

    0 讨论(0)
  • 2020-11-28 11:07

    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.

    0 讨论(0)
  • 2020-11-28 11:12

    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.

    0 讨论(0)
提交回复
热议问题