public static boolean isNetworkAvailable(Context context) {
try {
ConnectivityManager manager = (ConnectivityManager) NetworkUtils.getSystemService(context,
Context.CONNECTIVITY_SERVICE);
if (manager !=null) {
NetworkInfo[] networkInfos = manager.getAllNetworkInfo();
if (networkInfos !=null) {
for (NetworkInfo networkInfo : networkInfos) {
if (networkInfo !=null && networkInfo.isConnected()) {
return true;
}
}
}
}
}catch (Exception e) {
}
return false;
}
网友评论