的我有一個測試,如果WiFi連接可用代碼。Wifi連接工作inspite接入點
public boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
try {
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(3000);
urlc.setReadTimeout(4000);
urlc.connect();
if (urlc.getResponseCode() == HttpURLConnection.HTTP_OK) {
Log.i(TAG,"Internet connection is OK");
return true;
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ie) {
ie.printStackTrace();
}
}
Log.i(TAG, "No internet connection.");
return false;
}
訪問互聯網,我必須通過接入點,這就是爲什麼我espacially平谷歌,因爲我需要的,如果我們也是。我已經注意到登錄,在許多情況下,沉綿我不記錄進入強制門戶,代碼窗口達到谷歌並返回true。我也能夠上網服務器,比如ftp。 有誰知道這種行爲的原因是什麼?有沒有其他人注意到這種行爲?
謝謝
我沒有看到你ping通谷歌。也不是登錄。也不是一個俘虜門戶。無論如何。 – greenapps