我如何检查互联网是否有。但我找到了这段代码,但是当 wifi 连接时它返回 true,但我知道没有互联网。不能访问网络。
public boolean chechInternet_con(){
ConnectivityManager connec = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi =connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Here if condition check for wifi and mobile network is available or not.
// If anyone of them is available or connected then it will return true, otherwise false;
if (wifi.isConnected() || mobile.isConnected()) {
return true;
}
return false;
}