private boolean isConnectivity() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
ConnectivityManager cm = getSystemService(ConnectivityManager.class);
Network network = cm.getActiveNetwork();
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
LinkProperties linkProperties = cm.getLinkProperties(network);
if (caps == null || linkProperties == null) {
Toast.makeText(this, "您没有联网, 请联网后再打开.", Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
return true;
}
官方文档 ===> Android Developers