判断当前网络是否为 Wifi 网络
/** * 判断当前网络是否为 Wifi 网络连接 * @param context * @return */ private static boolean WifiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } return false; }
判断当前是否有网络连接
/** * 判断当前是否有网络连接 * @param context * @return */public boolean NetworkConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isAvailable()){ // 判断网络连接是否打开 return networkInfo.isConnected(); } return false;}