//判断是否有网络 public static boolean isNetWorkConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isAvailable(); } } return false; } //判断是否有wifi public static boolean isWifiConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiworkInfo != null) { return wifiworkInfo.isAvailable(); } } return false; } //判断Mobile网络是否可用 public static boolean isMobileConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileworkInfo != null) { return mobileworkInfo.isAvailable(); } } return false; } //获取当前网络连接的类型信息 public static int getConnectedType(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkworkInfo = connectivityManager.getActiveNetworkInfo(); if (networkworkInfo != null && networkworkInfo.isAvailable()) { return networkworkInfo.getType(); } } return -1; } }
05-11
05-07