如何连接到AVD
我试图写我自己的Android HTTP服务器。这是相当确定的,但我和我的AVD的一个问题。我不希望我的应用程序下载到手机,每次我要测试的变化。我想通过AVD连接到我的应用程序。
要获取IP地址,我使用这个功能:
i'm trying to write my own android http server. It's quite OK but i have a problem with my AVD. I don't want to download my app to phone everytime I want to test changes. I would like to connect to my app via AVD. To get the ip address i'm using this function:
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;
}
这是我的手机一切正常良好,但是当我在AVD运行我的应用程序是否显示IP:10.0.2.15
而且我无法连接到它。
有没有什么办法可以连接到AVD运行我的应用程序?
如果确实如此重要我的应用程序使用端口8080。
on my phone everything works good, but when i run my app on AVD it shows ip: 10.0.2.15 and i'm unable to connect to it. Is there any way to connect to my app running on AVD ? If it does matter my app uses port 8080.
远程登录到设备(假设它是在端口5554):
Telnet into the device (assuming it is on port 5554):
远程登录本地主机5554
telnet localhost 5554
在Android的控制台提示符下使用重定向:
At the Android console prompt use a redirect:
再导向添加TCP:8080:8080
redir add tcp:8080:8080
浏览器指向http://127.0.0.1:8080/现在应该发送和接收的AVD。
Pointing your browser to 'http://127.0.0.1:8080/' should now send, and receive to the AVD.