简体   繁体   中英

Android: host is not reachable

I just run the below code as a normal java class file and status.isReachable(3000) returns 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. Why is it returning false? Will it always returns false in the Emulator. I had also read this post [why-inetaddress-getbyname-isreachable-works-on-device-but-not-on-the-eclipse][1]

What I have done so far:

-kept the permission on the mainfest file

<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

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. (obviously XXXX was the IP address for my DNS server).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM