public static NetworkType getNetworkType(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo info = cm.getActiveNetworkInfo();
        if (info == null || !info.isConnectedOrConnecting()) {
            return NetworkType.NONE;
        }
        int type = info.getType();
        if (ConnectivityManager.TYPE_WIFI == type) {
            return NetworkType.WIFI;
        } else if (ConnectivityManager.TYPE_MOBILE == type) {
            return NetworkType.MOBILE;
        } else {
            return NetworkType.OTHER;
        }
    }
public static NetworkType getNetworkType ( Context context ) { ConnectivityManager cm = ( ConnectivityManager ) context . getSystemService ( Context . CONNECTIVITY_SERVICE ) ; final NetworkInfo info = cm . getActiveNetworkInfo ( ) ; if ( info == null || ! info . isConnectedOrConnecting ( ) ) { return NetworkType . NONE ; } int type = info . getType ( ) ; if ( ConnectivityManager . TYPE_WIFI == type ) { return NetworkType . WIFI ; } else if ( ConnectivityManager . TYPE_MOBILE == type ) { return NetworkType . MOBILE ; } else { return NetworkType . OTHER ; } }
获取当前网络类型

@return 返回网络类型