(How) Can an android virtual device use the local computer's internet?

早过忘川 提交于 2020-01-09 05:14:09

问题


I have a server running on the network my computer is on. Is there a way to allow the virtual device to use this same network and access the server? The virtual device won't let me toggle the wifi (probably because it doesn't have one). The only options I see that look right are:

"Wireless & network settings" --> "Mobile networks" --> "Access point names".

I'm not sure what to fill into all these fields though. If someone has an example of all the fields that are necessary to use the local computers internet, I'd appreciate it.

The virtual device is emulating my Droid X (API 2.2). I'm not looking for answers on how to communicate with the server but to get on the net and possibly a simple test to verify I'm on (right now I'm just using the ConnectivityManager to check)


回答1:


https://developer.android.com/studio/run/emulator-networking.html

As noted therein:

"Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall."

So you'll need to use the server's public IP (as opposed to it's local network IP).




回答2:


you dont need to do so much thing.

Just use your machine's ip to achieve this.

Suppose your machine(server) ip is 192.168.1.1

Then from your application just use http://192.168.1.1/your_appliction/webpage

If you want to access http://localhost/ just use http://10.0.2.2/




回答3:


To enable/toggle Wi-fi you need to go the Dev Tools option. That should do.



来源:https://stackoverflow.com/questions/5224474/how-can-an-android-virtual-device-use-the-local-computers-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!