我需要知道我的设备是否连接了互联网.我找到了很多答案,比如:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
(取自Detect whether there is an Internet connection available on Android.)
但这是不对的,例如,如果我是connected to a wireless network which doesn't have Internet access,这个方法将返回true…Is there a way to tell if the device has Internet connection and not if it is only connected to something?