//这是一个工具类 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) {//wifi网络 netType = 1; } //返回 return netType; } //加权限 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>