Example usage for android.net NetworkInfo getSubtype

List of usage examples for android.net NetworkInfo getSubtype

Introduction

In this page you can find the example usage for android.net NetworkInfo getSubtype.

Prototype

@Deprecated
public int getSubtype() 

Source Link

Document

Return a network-type-specific integer describing the subtype of the network.

Usage

From source file:com.sonetel.ui.dialpad.DialerFragment.java

protected boolean isInternetAvail(Context context) {
    connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = connectivityManager.getActiveNetworkInfo();

    if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
        Log.d(THIS_FILE, "Wifi state is now " + ni.getState().name());
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        }/*from w w w .  ja v  a  2 s.  c  om*/
    }
    if (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE) {
        // Any mobile network connected
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            int subType = ni.getSubtype();

            // 3G (or better)
            if (subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
                return true;
            }

            // GPRS (or unknown)
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS
                    || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                return true;
            }

            // EDGE
            if (subType == TelephonyManager.NETWORK_TYPE_EDGE) {
                return true;
            }
        }
    }
    if (ni != null && ni.getType() != ConnectivityManager.TYPE_MOBILE
            && ni.getType() != ConnectivityManager.TYPE_WIFI) {
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        }
    }
    return false;

}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

private void processNetworkType(Intent intent, Context context) {
    int netType;//  w w w .  ja  v  a 2s .  c om
    int netSubtype;
    int networkType;
    boolean isConnected;
    String reloadUrl;
    DebugLog.d(TAG, "processNetworkType() enter");

    NetworkInfo netInfo = Utils.getCurNetworkInfo(context);
    if (netInfo == null || netInfo.isAvailable() == false) {
        DebugLog.d(TAG, "getCurNetworkInfo() is null");
        netInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    }

    if (netInfo == null || netInfo.isAvailable() == false) {
        DebugLog.d(TAG, "getCurNetworkInfo() netInfo is null line1383");
        if (mbNetworIsConnect != false) {
            mbNetworIsConnect = false;
            reloadUrl = GameInfo.getErrorUrl();
            reload(reloadUrl);
        }
        Utils.setNetworkType(Constants.NETWORKTYPE_NONE);
        return;
    }
    netType = netInfo.getType();
    netSubtype = netInfo.getSubtype();
    isConnected = netInfo.isConnected();
    DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype
            + ",isConnect = " + isConnected);
    switch (netType) {
    case ConnectivityManager.TYPE_MOBILE_SUPL:
    case ConnectivityManager.TYPE_MOBILE_MMS:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE:
        DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE netSubtype=" + netSubtype);
        if (netSubtype == TelephonyManager.NETWORK_TYPE_LTE) {//4
            DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 4G");
            networkType = Constants.NETWORKTYPE_LTE;
        } else {//3
            DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 3G");
            networkType = Constants.NETWORKTYPE_3G;
        }
        break;
    case ConnectivityManager.TYPE_WIFI:
        DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_WIFI");
        networkType = Constants.NETWORKTYPE_WIFI;
        break;
    case ConnectivityManager.TYPE_ETHERNET:
        DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_ETHERNET");
        networkType = Constants.NETWORKTYPE_ETHERNET;
        break;
    default:
        DebugLog.d(TAG, "other network status");
        networkType = Constants.NETWORKTYPE_OTHERS;
        break;
    }
    DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype
            + ",isConnect = " + isConnected + ",mbNetworIsConnect = " + mbNetworIsConnect);
    if (isConnected) {
        reloadUrl = Utils.checkUrl(GameInfo.DEFAULT_URL);
        Utils.setNetworkType(networkType);
        //         Utils.setNetworkType(Constants.NETWORKTYPE_WIFI);//temp change
    } else {
        reloadUrl = GameInfo.getErrorUrl();
        Utils.setNetworkType(Constants.NETWORKTYPE_NONE);
    }

    //      if((networkType == Constants.NETWORKTYPE_WIFI || networkType == Constants.NETWORKTYPE_LTE) && mbNetworIsConnect != isConnected){
    if (mbNetworIsConnect != isConnected) {
        mbNetworIsConnect = isConnected;
        reload(reloadUrl);
        DebugLog.d(TAG, "Notify reload finish");
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*from   w  w w .  j  a v a 2 s .co m*/
 */
public int getAPType(String id) {
    if (apIds == null) {
        getAPIds();
    }
    NetworkInfo info = (NetworkInfo) apIds.get(id);
    if (info == null) {
        return NetworkManager.ACCESS_POINT_TYPE_UNKNOWN;
    }
    int type = info.getType();
    int subType = info.getSubtype();
    if (type == ConnectivityManager.TYPE_WIFI) {
        return NetworkManager.ACCESS_POINT_TYPE_WLAN;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 400-7000 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G;
        }
    } else {
        return NetworkManager.ACCESS_POINT_TYPE_UNKNOWN;
    }
}