public static boolean isNetworkConnected(Context context){
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if(network != null){
return network.isAvailable();
}
return false;
}
用这个
private boolean isOnline() {
ConnectivityManager connec = (ConnectivityManager)getSystemService(getApplicationContext().CONNECTIVITY_SERVICE);
return connec.getNetworkInfo(0).isConnectedOrConnecting();
}
总是返回false
标签:return,network,cm,可用,ConnectivityManager,网络,与否,boolean,false From: https://blog.51cto.com/u_16166892/6523950