// Path: utilslibrary/src/main/java/com/devin/UtilManager.java
// public class UtilManager {
// 
//     private static Context mContext;
// 
//     /**
//      * 初始化工具类集合
//      * @param context  context
//      */
//     public static void init(Context context) {
//         mContext = context.getApplicationContext();
//     }
// 
//     public static Context getContext() {
//         return mContext;
//     }
// }


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import com.devin.UtilManager;
package com.devin.util;



/**
 * <p>Description: 关于设备网络的工具类
 * <p>Company：
 * <p>Email:bjxm2013@163.com
 * <p>Created by Devin Sun on 2017/4/26.
 */

public class NetworkUtils {

    /**
     * 未知网络
     */
    public static final int NETWORK_TYPE_UNKNOWN = 0;

    /**
     * 没有网络
     */
    public static final int NETWORK_TYPE_INVALID = 0;
    /**
     * wap网络
     */
    public static final int NETWORK_TYPE_WAP = 1;
    /**
     * 2G网络
     */
    public static final int NETWORK_TYPE_2G = 2;

    /**
     * 3G网络
     */
    public static final int NETWORK_TYPE_3G = 3;

    /**
     * 4G网络
     */
    public static final int NETWORK_TYPE_4G = 4;

    /**
     * wifi网络
     */
    public static final int NETWORK_TYPE_WIFI = 10;

    /**
     * 检查是否有网络
     *
     * @return true 有网，false 无网
     */
    public static boolean isAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager) UtilManager.getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager
                .getActiveNetworkInfo();

        return activeNetworkInfo != null;
    }

    /**
     * 判断是否是wifi连接
     *
     * @return true wifi,false 非wifi
     */
    public static boolean isWifi() {
        ConnectivityManager connectivityManager = (ConnectivityManager) UtilManager.getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return wifiNetworkInfo.isConnected();

    }


    /**
     * 获取网络状态，wifi,wap,2g,3g,4g.
     *
     * @return int 网络状态 {@link #NETWORK_TYPE_2G},{@link #NETWORK_TYPE_3G},{@link #NETWORK_TYPE_4G}
     * {@link #NETWORK_TYPE_INVALID},{@link #NETWORK_TYPE_WAP},
     * {@link #NETWORK_TYPE_WIFI}
     */
    public static int getNetworkType() {
        int strNetworkType = NETWORK_TYPE_INVALID;

        NetworkInfo networkInfo = ((ConnectivityManager) UtilManager.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
// Path: utilslibrary/src/main/java/com/devin/UtilManager.java
// public class UtilManager {
// 
//     private static Context mContext;
// 
//     /**
//      * 初始化工具类集合
//      * @param context  context
//      */
//     public static void init(Context context) {
//         mContext = context.getApplicationContext();
//     }
// 
//     public static Context getContext() {
//         return mContext;
//     }
// }


// Path: utilslibrary/src/main/java/com/devin/util/NetworkUtils.java
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import com.devin.UtilManager;

package com.devin.util;



/**
 * <p>Description: 关于设备网络的工具类
 * <p>Company：
 * <p>Email:bjxm2013@163.com
 * <p>Created by Devin Sun on 2017/4/26.
 */

public class NetworkUtils {

    /**
     * 未知网络
     */
    public static final int NETWORK_TYPE_UNKNOWN = 0;

    /**
     * 没有网络
     */
    public static final int NETWORK_TYPE_INVALID = 0;
    /**
     * wap网络
     */
    public static final int NETWORK_TYPE_WAP = 1;
    /**
     * 2G网络
     */
    public static final int NETWORK_TYPE_2G = 2;

    /**
     * 3G网络
     */
    public static final int NETWORK_TYPE_3G = 3;

    /**
     * 4G网络
     */
    public static final int NETWORK_TYPE_4G = 4;

    /**
     * wifi网络
     */
    public static final int NETWORK_TYPE_WIFI = 10;

    /**
     * 检查是否有网络
     *
     * @return true 有网，false 无网
     */
    public static boolean isAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager) UtilManager.getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager
                .getActiveNetworkInfo();

        return activeNetworkInfo != null;
    }

    /**
     * 判断是否是wifi连接
     *
     * @return true wifi,false 非wifi
     */
    public static boolean isWifi() {
        ConnectivityManager connectivityManager = (ConnectivityManager) UtilManager.getContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return wifiNetworkInfo.isConnected();

    }


    /**
     * 获取网络状态，wifi,wap,2g,3g,4g.
     *
     * @return int 网络状态 {@link #NETWORK_TYPE_2G},{@link #NETWORK_TYPE_3G},{@link #NETWORK_TYPE_4G}
     * {@link #NETWORK_TYPE_INVALID},{@link #NETWORK_TYPE_WAP},
     * {@link #NETWORK_TYPE_WIFI}
     */
    public static int getNetworkType() {
        int strNetworkType = NETWORK_TYPE_INVALID;

        NetworkInfo networkInfo = ((ConnectivityManager) UtilManager.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {