2
请检查下面的代码requestRouteToHost始终返回false
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
int networkType = ConnectivityManager.TYPE_WIFI;
return cm.requestRouteToHost(networkType, lookupHost("http://www.ati.ag"));
//return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
public static int lookupHost(String hostname) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(hostname);
} catch (UnknownHostException e) {
return -1;
}
byte[] addrBytes;
int addr;
addrBytes = inetAddress.getAddress();
addr = ((addrBytes[3] & 0xff) << 24)
| ((addrBytes[2] & 0xff) << 16)
| ((addrBytes[1] & 0xff) << 8)
| (addrBytes[0] & 0xff);
System.out.println(addr);
return addr;
}
isOnline总是返回false,请帮它是如何工作的? 或者请告诉我有关检查服务器连接 基本目的的任何其他方式是检查,互联网可在本地WiFi或不
没有,还没有成型 – Ali 2011-12-16 13:22:32
现在我知道有一个古老的悬而未决的问题有关。一个可能的解释是它没有被执行。请参阅:http://stackoverflow.com/a/2680765/972850 – gimix 2011-12-16 14:42:37