package baidu.com.commontools.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtils {

    private static ConnectivityManager sCM;

    private static ConnectivityManager getConnectiveManager(Context cxt) {
        if (sCM == null) {
            Context appCxt = cxt.getApplicationContext();
            sCM = (ConnectivityManager) appCxt.getSystemService(Context.CONNECTIVITY_SERVICE);
        }
        return sCM;
    }

    public boolean isConnected(Context cxt) {
        ConnectivityManager cm = getConnectiveManager(cxt);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        return networkInfo != null && networkInfo.isConnected();
    }
}

@@ -139,82 +139,328 @@
 fo;%0A
-%0Apublic class NetworkUtils %7B%0A%0A    private static ConnectivityManager sCM;%0A
+import android.support.annotation.Nullable;%0A%0Apublic class NetworkUtils %7B%0A%0A    public static final int NET_TYPE_NONE = 1;%0A    public static final int NET_TYPE_APN = 2;%0A    public static final int NET_TYPE_WIFI = 3;%0A%0A    private static ConnectivityManager sCM;%0A%0A    /**%0A     * get connectivityManager%0A     */%0A    @Nullable
 %0A   
@@ -748,16 +748,73 @@
 %0A    %7D%0A%0A
+    /**%0A     * check if the network is available%0A     */%0A
     publ
@@ -826,16 +826,23 @@
 olean is
+Network
 Connecte
@@ -930,21 +930,48 @@
     
-NetworkInfo n
+if (cm == null) return false;%0A%0A        N
 etwo
@@ -977,16 +977,21 @@
 orkInfo 
+info 
 = cm.get
@@ -1030,56 +1030,782 @@
 urn 
-networkInfo != null && networkInfo.isConnected()
+info.isConnected();%0A    %7D%0A%0A    /**%0A     * get network type%0A     */%0A    public static int getNetworkType(Context cxt) %7B%0A        ConnectivityManager cm = getConnectiveManager(cxt);%0A        if (cm == null) return NET_TYPE_NONE;%0A%0A        NetworkInfo info = cm.getActiveNetworkInfo();%0A        int type = info.getType();%0A        int subType = info.getSubtype();%0A        if (type == ConnectivityManager.TYPE_WIFI%0A                %7C%7C type == ConnectivityManager.TYPE_WIMAX%0A                %7C%7C type == ConnectivityManager.TYPE_ETHERNET) %7B%0A            return NET_TYPE_WIFI;%0A        %7D else if (type == ConnectivityManager.TYPE_MOBILE%0A                %7C%7C (type == ConnectivityManager.TYPE_BLUETOOTH && subType %3E 0)) %7B%0A            return NET_TYPE_APN;%0A        %7D%0A        return NET_TYPE_NONE
 ;%0A  

change : add getNetworkType method.