Android的连接到电脑的本地主机上时,移动设备调试 [英] android connect to PC's localhost when debugger on mobile device

查看:176
本文介绍了Android的连接到电脑的本地主机上时,移动设备调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试我的Andr​​oid应用程序,我的Andr​​oid设备连接到使用USB电缆我的电脑。在我的应用程序有一个按钮,与本地主机连接时,IP为本地主机的 10.0.2.2 和端口 8080 ,我已阅读,手机上调试时,在IP 10.0.2.2 是本地主机的Andr​​oid设备,而不是我的电脑,所以我应该做的知识产权什么样的变化,而不是对 10.0.2.2 ?或者我必须做出的另一个变化? 在这种情况下,我的Andr​​oid设备是索尼爱立信Xperia Arc小号

I want to debug my android application, I connect the android device to my PC using the USB cable. In my application there is a button to connect with localhost, ip for localhost is 10.0.2.2 and the port is 8080, I have read that when debugging on mobile, the ip 10.0.2.2 is the localhost for android device and not for my PC, so what changes should I make to the ip instead of 10.0.2.2? or do I have to make another change? In this case my android device is sony ericsson xperia arc s.

推荐答案

由于 10.0.2.2 是你的系统(PC)的本地主机地址(仅模拟器)。其实Android不认识的本地主机的URL。所以 10.0.2.2 是指意思。同样为Android设备的回送地址是 127.0.0.1

As 10.0.2.2 is your system (pc)'s local host address (from emulator only). Actually android doesn't recognized localhost in url. so 10.0.2.2 is for that meant. Also for android device loopback address is 127.0.0.1.

您的网址与10.0.2.2是正确的。你也可以使用静态IP 您的系统。

Your url with 10.0.2.2 is correct. Also you can use Static IP of your system.

只是检查

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

在应用程序的清单文件。

in your application's manifest file.

编辑:

在这里,您使用的是8080端口的话,尝试与 ADB命令您的主机上。

Here you are using port 8080 so, try with adb command on your host machine.

adb forward tcp:8080 tcp:8080

另外,请在此行细说我想我的调试器的应用程序在我的手机

注意:

如果你要测试在真实设备上使用您的网络IP 系统(PC)的。

If you are going to test on real device use your Network IP of system (PC).

这篇关于Android的连接到电脑的本地主机上时,移动设备调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆