Android 如何连接到AVD

Android 如何连接到AVD,android,connect,avd,Android,Connect,Avd,我正在尝试编写自己的android http服务器。很好,但我的AVD有问题。我不想每次测试更改时都将我的应用下载到手机上。我想通过AVD连接到我的应用程序。 要获取ip地址,我正在使用此函数: private String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();

我正在尝试编写自己的android http服务器。很好,但我的AVD有问题。我不想每次测试更改时都将我的应用下载到手机上。我想通过AVD连接到我的应用程序。 要获取ip地址,我正在使用此函数:

private String getLocalIpAddress() {


        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); }
                }
            }
        } catch (SocketException ex) {
            Log.e("ServerActivity", ex.toString());
        }
        return null;
    }
私有字符串getLocalIpAddress(){
试一试{
对于(枚举en=NetworkInterface.getNetworkInterfaces();en.hasMoreElements();){
NetworkInterface intf=en.nextElement();
对于(枚举Enumeration EnumipAddress=intf.getInetAddresses();EnumipAddress.hasMoreElements();){
InetAddress InetAddress=enumIpAddr.nextElement();
如果(!inetAddress.isLoopbackAddress()){return inetAddress.getHostAddress().toString();}
}
}
}捕获(SocketException例外){
Log.e(“ServerActivity”,例如toString());
}
返回null;
}
在我的手机上,一切正常,但当我在AVD上运行我的应用程序时,它显示ip:10.0.2.15 我无法连接到它。 有没有办法连接到我在AVD上运行的应用程序?
如果有关系,我的应用程序使用端口8080。

虽然我不知道您的问题的直接答案,但我知道,当从AVD连接到您的计算机时,您必须使用10.0.2.2,因为您的AVD基本上位于另一个“路由器”后面。它无法从路由器获取本地lan IP。有关更多信息,请参见问题。他在link中引用:

模拟器的每个实例都在虚拟路由器/防火墙后面运行 将其与开发计算机的网络隔离的服务 接口和设置,以及从internet获取的信息。模拟设备可以 在上看不到您的开发计算机或其他仿真器实例 网络。相反,它只看到它是通过以太网连接的 到路由器/防火墙

远程登录到设备(假设它位于端口5554上):

telnet本地主机5554

在Android控制台提示下,使用重定向:

重拨添加tcp:8080:8080

将浏览器指向'http://127.0.0.1:8080/'现在应该发送和接收到AVD

承蒙:

目前还不清楚“redir”命令的来源,最新图像中没有该命令。