package com.bwie.pulllibrary.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; /** * author:Created by WangZhiQiang on 2017-09-05. */ public class NetTypeUtil { /** * @param context * @return 返回值 -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; } }