public static boolean isNetworkAvailable(Context context) { ConnectivityManager connm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connm == null) { return false; } else { NetworkInfo[] nis = connm.getAllNetworkInfo(); if (nis != null) { for (int i = 0; i < nis.length; i++) { if (nis[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
时间: 2024-09-28 13:48:35