我跟着这个 http://www.helloandroid.com/tutorials/it-internet-connection-checker-snippet检查我的Android设备上是否有互联网连接。Android - 检查互联网连接(使用开放的Wifi点,需要登录)
的代码块看起来像这样
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setConnectTimeout(1000 * 5); // Timeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
// http response is OK
Log.d("db", "Connection to " + url.toString() + " successful!");
return true;
}
然而,我的设备连接到打开需要的网页访问互联网之前登录的WiFi点。此代码似乎即使没有登录也会返回true。
想知道我能做什么吗?
你想检查无线网络或互联网连接可用 – Newts 2012-02-01 10:16:27
什么是您提交的网址形式? – Zakaria 2012-02-01 10:28:46
其实我正在关注[link](http://www.helloandroid.com/tutorials/it-internet-connection-checker-snippet)我想做一些类似于“ping”的事情来确认实际上有一个互联网连接而不仅仅是一个网络(wifi/3G)连接。 Wifi和3G连接不足以确定我已连接到互联网。 – humansg 2012-02-01 11:57:23