直接上此工具类 public class InternetUtil { /** * 返回值 -1:没有网络 1:WIFI网络 2:net网络 */ public static int getNetype(Context context) { int netType = -1; ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo == null) { return netType; } int nType = networkInfo.getType(); if (nType == ConnectivityManager.TYPE_MOBILE) { netType = 2; } else if (nType == ConnectivityManager.TYPE_WIFI) { netType = 1; } return netType; } }