在设备中,当我启用互联网数据时,它在网络中显示 E。但我的 sim 卡中没有数据包,并且互联网无法在任何应用程序中运行。我已经使用了这段代码,它返回了互联网存在的真实情况。在这种情况下,如何确定互联网是否正常工作:
public static boolean isConnectingToInternetLatest(Context mContext) {
ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Network[] networks = connectivityManager.getAllNetworks();
NetworkInfo networkInfo;
for (Network mNetwork : networks) {
networkInfo = connectivityManager.getNetworkInfo(mNetwork);
if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
return true;
}
}
} else {
if (connectivityManager != null) {
//noinspection deprecation
NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
if (info != null) {
for (NetworkInfo anInfo : info) {
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
//Log.d("Network", "NETWORK NAME: " + anInfo.getTypeName());
return true;
}
}
}
}
}
return false;
}