public boolean isWifiAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected() && networkInfo .getType() == ConnectivityManager.TYPE_WIFI); } /** * 判断当前网络是否是4G网络 * * @param * @return boolean */ public boolean is4GAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) { TelephonyManager telephonyManager = (TelephonyManager) getActivity().getSystemService( Context.TELEPHONY_SERVICE); int networkType = telephonyManager.getNetworkType(); /** Current network is LTE */ if (networkType == 13) { /**此时的网络是4G的*/ return true; } } return false; }