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