[英]Android: host is not reachable
I just run the below code as a normal java class file and status.isReachable(3000) returns true. 我只是将以下代码作为普通的Java类文件运行,并且status.isReachable(3000)返回true。
InetAddress status = InetAddress.getByName("android.com");
status.isReachable(3000);
If i run the same code from the Android Project, status.isReachable(3000)
always return false. 如果我从Android Project运行相同的代码,则
status.isReachable(3000)
始终返回false。 Why is it returning false? 为什么返回假? Will it always returns false in the Emulator.
它会在模拟器中始终返回false吗? I had also read this post [why-inetaddress-getbyname-isreachable-works-on-device-but-not-on-the-eclipse][1]
我也读过这篇文章[为什么inetaddress-getbyname-isreachable-work-on-devices在设备上工作但不在日食上[1]
What I have done so far: 到目前为止,我所做的是:
-kept the permission on the mainfest file -保留对mainfest文件的权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
-disable my firewall. -禁用我的防火墙。
-ping the android.com from my PC, the host is reachable 从我的PC ping android.com,主机可访问
I was doing this to check whether the address in the preference is dead or alive 我这样做是为了检查首选项中的地址是死的还是活的
I had a similar kind of problem where my map app background was grey (no tiles) and the browser was unable to connect to the internet. 我遇到了类似的问题,其中我的地图应用背景为灰色(没有图块),并且浏览器无法连接到互联网。
Within Eclipse I went to Run Configurations -> Target and added "-dns-server XXXX" and everything worked fine afterwards. 在Eclipse中,我转到“运行配置”->“目标”,并添加了“ -dns-server XXXX”,之后一切正常。 (obviously XXXX was the IP address for my DNS server).
(显然XXXX是我的DNS服务器的IP地址)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.