如何从 Android Studio 模拟器连接到本地主机

如何从 Android Studio 模拟器连接到本地主机

问题描述:

我正在尝试在 Android 2.3.3 浏览器中测试 Web 应用程序.使用http://10.0.2.2 的连接结果网页不可用".Android Studio 文档中未找到任何内容.

I am trying to test web application in Android 2.3.3 browser. Connection using http://10.0.2.2 results "web page is unavailable". Nothing found in Android Studio documentation.

有人遇到同样的问题吗?你是怎么解决的?

Does anyone run into the same problem? How did you solve it?

您将需要连接到计算机的 IP.

You're going to need to connect to your computer's IP.

如果您使用的是 Windows,请打开 CMD 并输入 ipconfig,这将为您提供本地 IP.

If you're on Windows open CMD and type ipconfig this will give you your local IP.

如果您使用的是 Linux 或 OSX,请打开终端并使用 ifconfig 命令.

If you're on Linux or OSX open terminal and use the ifconfig command.

由于模拟器是一个完整的 Android 设备,它有自己的网络,并且不使用与您的机器相同的主机文件.加上自己的IP.

Since the emulator is a full Android device it has its own network and doesn't use the same hosts file that your machine has. Along with its own IP.

语法修复.