Java Code Examples for android.telephony.TelephonyManager#NETWORK_TYPE_1xRTT

The following examples show how to use android.telephony.TelephonyManager#NETWORK_TYPE_1xRTT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellBackendHelper.java    From android_external_UnifiedNlpApi with Apache License 2.0 6 votes vote down vote up
private static Cell.CellType getCellType(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return Cell.CellType.GSM;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return Cell.CellType.UMTS;
        case TelephonyManager.NETWORK_TYPE_LTE:
            return Cell.CellType.LTE;
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return Cell.CellType.CDMA;
    }
    return null;
}
 
Example 2
Source File: Depr_CellsInfoDataCollector.java    From DataLogger with MIT License 6 votes vote down vote up
private static String networkTypeGeneral(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_LTE:
            return "4G";
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return "3G";
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return "2G";
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return "CDMA";
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return "Unknown";
    }
}
 
Example 3
Source File: NetworkUtil.java    From RxZhihuDaily with MIT License 5 votes vote down vote up
private static String getNetworkTypeNameInMobile(int type) {
    switch (type) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return "GPRS";
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return "EDGE";
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return "UMTS";
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return "HSDPA";
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return "HSUPA";
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return "HSPA";
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return "CDMA";
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return "CDMA - EvDo rev. 0";
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return "CDMA - EvDo rev. A";
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return "CDMA - EvDo rev. B";
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return "CDMA - 1xRTT";
        case TelephonyManager.NETWORK_TYPE_LTE:
            return "LTE";
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return "CDMA - eHRPD";
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return "iDEN";
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return "HSPA+";
        default:
            return "UNKNOWN";
    }
}
 
Example 4
Source File: ImageLoaderUtil.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
private static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    switch (telephonyManager.getNetworkType()) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return true; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true; // ~ 400-7000 kbps
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return false; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE:
            return true; // ~ 10+ Mbps
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            return false;
        default:
            return false;
    }
}
 
Example 5
Source File: Network.java    From MarkdownEditors with Apache License 2.0 5 votes vote down vote up
/**
 * GPRS    2G(2.5) General Packet Radia Service 114kbps
 * EDGE    2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
 * UMTS    3G WCDMA 联通3G Universal Mobile Telecommunication System 完整的3G移动通信技术标准
 * CDMA    2G 电信 Code Division Multiple Access 码分多址
 * EVDO_0  3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 属于3G
 * EVDO_A  3G 1.8mbps - 3.1mbps 属于3G过渡,3.5G
 * 1xRTT   2G CDMA2000 1xRTT (RTT - 无线电传输技术) 144kbps 2G的过渡,
 * HSDPA   3.5G 高速下行分组接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps
 * HSUPA   3.5G High Speed Uplink Packet Access 高速上行链路分组接入 1.4 - 5.8 mbps
 * HSPA    3G (分HSDPA,HSUPA) High Speed Packet Access
 * IDEN    2G Integrated Dispatch Enhanced Networks 集成数字增强型网络 (属于2G,来自维基百科)
 * EVDO_B  3G EV-DO Rev.B 14.7Mbps 下行 3.5G
 * LTE     4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G过渡,升级版 LTE Advanced 才是4G
 * EHRPD   3G CDMA2000向LTE 4G的中间产物 Evolved High Rate Packet Data HRPD的升级
 * HSPAP   3G HSPAP 比 HSDPA 快些
 *
 * @return {@link  NetWorkType}
 */
public NetWorkType getNetworkType() {
    int type = getConnectedTypeINT();
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
            return NetWorkType.Wifi;
        case ConnectivityManager.TYPE_MOBILE:
        case ConnectivityManager.TYPE_MOBILE_DUN:
        case ConnectivityManager.TYPE_MOBILE_HIPRI:
        case ConnectivityManager.TYPE_MOBILE_MMS:
        case ConnectivityManager.TYPE_MOBILE_SUPL:
            int teleType = getTelephonyManager().getNetworkType();
            switch (teleType) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NetWorkType.Net2G;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return NetWorkType.Net3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetWorkType.Net4G;
                default:
                    return NetWorkType.UnKnown;
            }
        default:
            return NetWorkType.UnKnown;
    }
}
 
Example 6
Source File: NetCheck.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
/**
 * GPRS    2G(2.5) General Packet Radia Service 114kbps
 * EDGE    2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
 * UMTS    3G WCDMA 联通3G Universal Mobile Telecommunication System 完整的3G移动通信技术标准
 * CDMA    2G 电信 Code Division Multiple Access 码分多址
 * EVDO_0  3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 属于3G
 * EVDO_A  3G 1.8mbps - 3.1mbps 属于3G过渡,3.5G
 * 1xRTT   2G CDMA2000 1xRTT (RTT - 无线电传输技术) 144kbps 2G的过渡,
 * HSDPA   3.5G 高速下行分组接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps
 * HSUPA   3.5G High Speed Uplink Packet Access 高速上行链路分组接入 1.4 - 5.8 mbps
 * HSPA    3G (分HSDPA,HSUPA) High Speed Packet Access
 * IDEN    2G Integrated Dispatch Enhanced Networks 集成数字增强型网络 (属于2G,来自维基百科)
 * EVDO_B  3G EV-DO Rev.B 14.7Mbps 下行 3.5G
 * LTE     4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G过渡,升级版 LTE Advanced 才是4G
 * EHRPD   3G CDMA2000向LTE 4G的中间产物 Evolved High Rate Packet Data HRPD的升级
 * HSPAP   3G HSPAP 比 HSDPA 快些
 *
 * @return {@link  NetWorkType}
 */
public static NetWorkType getNetworkType(Context context) {
    int type = getConnectedTypeINT(context);
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
            return NetWorkType.Wifi;
        case ConnectivityManager.TYPE_MOBILE:
        case ConnectivityManager.TYPE_MOBILE_DUN:
        case ConnectivityManager.TYPE_MOBILE_HIPRI:
        case ConnectivityManager.TYPE_MOBILE_MMS:
        case ConnectivityManager.TYPE_MOBILE_SUPL:
            int teleType = getTelephonyManager(context).getNetworkType();
            switch (teleType) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NetWorkType.Net2G;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return NetWorkType.Net3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetWorkType.Net4G;
                default:
                    return NetWorkType.UnKnown;
            }
        default:
            return NetWorkType.UnKnown;
    }
}
 
Example 7
Source File: NetWorkUtils.java    From allenglish with Apache License 2.0 4 votes vote down vote up
/**
 * Whether is fast mobile network
 * 
 * @param context
 * @return
 */
private static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return false;
    }

    switch (telephonyManager.getNetworkType()) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false;
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false;
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false;
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return true;
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true;
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false;
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true;
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true;
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true;
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true;
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return true;
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return true;
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return true;
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return false;
        case TelephonyManager.NETWORK_TYPE_LTE:
            return true;
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            return false;
        default:
            return false;
    }
}
 
Example 8
Source File: TraceDeviceInfo.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static String getTelephonyHeader() {
	// Telephony manager can tell us a few things...
	String info = "";

	if (m_telephonyManager != null) {
		try { // getDeviceId() requires android.permission.READ_PHONE_STATE
			info = "<deviceid>" + m_telephonyManager.getDeviceId() + "</deviceid>";
		} catch (Exception e1) {
			DebugTool.logError("Failure getting telephony device ID: " + e1.toString(), e1);
		}

		info = "<pt>";
		switch (m_telephonyManager.getPhoneType()) {
			case TelephonyManager.PHONE_TYPE_NONE:
				info += "NONE";
				break;
			case TelephonyManager.PHONE_TYPE_GSM:
				info += "GSM";
				break;
			case TelephonyManager.PHONE_TYPE_CDMA:
				info += "CDMA";
				break;
			default:
				info += "UNKNOWN";
		} // end-switch

		info += "</pt>" + "<nt>";

		switch (m_telephonyManager.getNetworkType()) {
			case TelephonyManager.NETWORK_TYPE_UNKNOWN:
				info += "UKNOWN";
				break;
			case TelephonyManager.NETWORK_TYPE_GPRS:
				info += "GPRS";
				break;
			case TelephonyManager.NETWORK_TYPE_EDGE:
				info += "EDGE";
				break;
			case TelephonyManager.NETWORK_TYPE_UMTS:
				info += "UMTS";
				break;
			case TelephonyManager.NETWORK_TYPE_HSDPA:
				info += "HSDPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSUPA:
				info += "HSUPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSPA:
				info += "HSPA";
				break;
			case TelephonyManager.NETWORK_TYPE_CDMA:
				info += "CDMA";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_0:
				info += "EVDO_O";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_A:
				info += "EVDO_A";
				break;
			case TelephonyManager.NETWORK_TYPE_1xRTT:
				info += "1xRTT";
				break;
			default:
				info += "UNKNOWN";
				break;
		} // end-switch

		info += "</nt>";
	} // end-if
	return info;
}
 
Example 9
Source File: NetworkUtils.java    From AcgClub with MIT License 4 votes vote down vote up
/**
 * Return type of network.
 * <p>Must hold
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return type of network <ul> <li>{@link NetworkUtils.NetworkType#NETWORK_WIFI   } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_4G     } </li> <li>{@link
 * NetworkUtils.NetworkType#NETWORK_3G     } </li> <li>{@link NetworkUtils.NetworkType#NETWORK_2G
 * } </li> <li>{@link NetworkUtils.NetworkType#NETWORK_UNKNOWN} </li> <li>{@link
 * NetworkUtils.NetworkType#NETWORK_NO     } </li> </ul>
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static NetworkType getNetworkType() {
  NetworkType netType = NetworkType.NETWORK_NO;
  NetworkInfo info = getActiveNetworkInfo();
  if (info != null && info.isAvailable()) {

    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
      netType = NetworkType.NETWORK_WIFI;
    } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
      switch (info.getSubtype()) {

        case NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
          netType = NetworkType.NETWORK_2G;
          break;

        case NETWORK_TYPE_TD_SCDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
          netType = NetworkType.NETWORK_3G;
          break;

        case NETWORK_TYPE_IWLAN:
        case TelephonyManager.NETWORK_TYPE_LTE:
          netType = NetworkType.NETWORK_4G;
          break;
        default:

          String subtypeName = info.getSubtypeName();
          if (subtypeName.equalsIgnoreCase("TD-SCDMA")
              || subtypeName.equalsIgnoreCase("WCDMA")
              || subtypeName.equalsIgnoreCase("CDMA2000")) {
            netType = NetworkType.NETWORK_3G;
          } else {
            netType = NetworkType.NETWORK_UNKNOWN;
          }
          break;
      }
    } else {
      netType = NetworkType.NETWORK_UNKNOWN;
    }
  }
  return netType;
}
 
Example 10
Source File: RxNetTool.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
/**
 * 需添加权限
 *      @code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 *
 * 它主要负责的是
 *  1 监视网络连接状态 包括(Wi-Fi, 2G, 3G, 4G)
 *  2 当网络状态改变时发送广播通知
 *  3 网络连接失败尝试连接其他网络
 *  4 提供API,允许应用程序获取可用的网络状态
 *
 * netTyped 的结果
 * @link #NETWORK_NO      = -1; 当前无网络连接
 * @link #NETWORK_WIFI    =  1; wifi的情况下
 * @link #NETWORK_2G      =  2; 切换到2G环境下
 * @link #NETWORK_3G      =  3; 切换到3G环境下
 * @link #NETWORK_4G      =  4; 切换到4G环境下
 * @link #NETWORK_UNKNOWN =  5; 未知网络
 *
 * @param context 上下文
 * @return 网络类型
 */
public static int getNetWorkType(Context context) {
    // 获取ConnectivityManager
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo ni = cm.getActiveNetworkInfo();// 获取当前网络状态

    int netType = NETWORK_NO;

    if (ni != null && ni.isConnectedOrConnecting()) {

        switch (ni.getType()) {//获取当前网络的状态
            case ConnectivityManager.TYPE_WIFI:// wifi的情况下
                netType = NETWORK_WIFI;
                RxToast.success("切换到wifi环境下");
                break;
            case ConnectivityManager.TYPE_MOBILE:

                switch (ni.getSubtype()) {
                    case NETWORK_TYPE_GSM:
                    case TelephonyManager.NETWORK_TYPE_GPRS: // 联通2g
                    case TelephonyManager.NETWORK_TYPE_CDMA: // 电信2g
                    case TelephonyManager.NETWORK_TYPE_EDGE: // 移动2g
                    case TelephonyManager.NETWORK_TYPE_1xRTT:
                    case TelephonyManager.NETWORK_TYPE_IDEN:
                        netType = NETWORK_2G;
                        RxToast.info("切换到2G环境下");
                        break;
                    case TelephonyManager.NETWORK_TYPE_EVDO_A: // 电信3g
                    case TelephonyManager.NETWORK_TYPE_UMTS:
                    case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    case TelephonyManager.NETWORK_TYPE_HSDPA:
                    case TelephonyManager.NETWORK_TYPE_HSUPA:
                    case TelephonyManager.NETWORK_TYPE_HSPA:
                    case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    case TelephonyManager.NETWORK_TYPE_EHRPD:
                    case TelephonyManager.NETWORK_TYPE_HSPAP:
                    case NETWORK_TYPE_TD_SCDMA:
                        netType = NETWORK_3G;
                        RxToast.info("切换到3G环境下");
                        break;
                    case TelephonyManager.NETWORK_TYPE_LTE:

                    case NETWORK_TYPE_IWLAN:
                        netType = NETWORK_4G;
                        RxToast.info("切换到4G环境下");
                        break;
                    default:

                        String subtypeName = ni.getSubtypeName();
                        if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                                || subtypeName.equalsIgnoreCase("WCDMA")
                                || subtypeName.equalsIgnoreCase("CDMA2000")) {
                            netType = NETWORK_3G;
                        } else {
                            netType = NETWORK_UNKNOWN;
                        }
                        RxToast.normal("未知网络");
                }
                break;
            default:
                netType = 5;
                RxToast.normal("未知网络");
        }

    } else {
        netType = NETWORK_NO;
        RxToast.error(context, "当前无网络连接").show();
    }
    return netType;
}
 
Example 11
Source File: OSUtilities.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
private static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_CDMA:
                return false; // ~ 14-64 kbps
            case TelephonyManager.NETWORK_TYPE_EDGE:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_GPRS:
                return false; // ~ 100 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                return false; // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_LTE:
                return true; // ~ 400-1000 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                return true; // ~ 600-1400 kbps
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                return true; // ~ 2-14 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPA:
                return true; // ~ 700-1700 kbps
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                return true; // ~ 1-23 Mbps
            case TelephonyManager.NETWORK_TYPE_UMTS:
                return true; // ~ 400-7000 kbps
            case TelephonyManager.NETWORK_TYPE_EHRPD:
                return true; // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
                return true; // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                return true; // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return true; // ~ 10+ Mbps
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    } else {
        return false;
    }
}
 
Example 12
Source File: AbstractNetworkUtils.java    From tenor-android-core with Apache License 2.0 4 votes vote down vote up
/**
 * Checks network type and subtype, to determine if network is fast (in kbps)
 *
 * @param type    ConnectivityManager type
 * @param subType TelephonyManager type for mobile
 * @return true if device is connected to a fast network connection
 */
private static boolean isNetworkConnected(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) return true;

    if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                return false; // ~ 50-100 kbps

            case TelephonyManager.NETWORK_TYPE_CDMA:
                return false; // ~ 14-64 kbps

            case TelephonyManager.NETWORK_TYPE_EDGE:
                return false; // ~ 50-100 kbps

            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                return true; // ~ 400-1000 kbps

            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                return true; // ~ 600-1400 kbps

            case TelephonyManager.NETWORK_TYPE_GPRS:
                return false; // ~ 100 kbps

            case TelephonyManager.NETWORK_TYPE_HSDPA:
                return true; // ~ 2-14 Mbps

            case TelephonyManager.NETWORK_TYPE_HSPA:
                return true; // ~ 700-1700 kbps

            case TelephonyManager.NETWORK_TYPE_HSUPA:
                return true; // ~ 1-23 Mbps

            case TelephonyManager.NETWORK_TYPE_UMTS:
                return true; // ~ 400-7000 kbps

            case TelephonyManager.NETWORK_TYPE_EHRPD:
                return true; // ~ 1-2 Mbps

            case TelephonyManager.NETWORK_TYPE_EVDO_B:
                return true; // ~ 5 Mbps

            case TelephonyManager.NETWORK_TYPE_HSPAP:
                return true; // ~ 10-20 Mbps

            case TelephonyManager.NETWORK_TYPE_IDEN:
                return false; // ~25 kbps

            case TelephonyManager.NETWORK_TYPE_LTE:
                return true; // ~ 10+ Mbps

            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    }
    return false;
}
 
Example 13
Source File: EasyNetworkMod.java    From easydeviceinfo with Apache License 2.0 4 votes vote down vote up
/**
 * Gets network type.
 *
 * You need to declare the below permission in the manifest file to use this properly
 *
 * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 * <uses-permission android:name="android.permission.INTERNET"/>
 *
 * @return the network type
 */
@RequiresPermission(allOf = {
    Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.INTERNET
})
@NetworkType
public final int getNetworkType() {
  int result = NetworkType.UNKNOWN;
  if (PermissionUtil.hasPermission(context, Manifest.permission.ACCESS_NETWORK_STATE)) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (cm != null) {
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      if (activeNetwork == null) {
        result = NetworkType.UNKNOWN;
      } else if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI
          || activeNetwork.getType() == ConnectivityManager.TYPE_WIMAX) {
        result = NetworkType.WIFI_WIFIMAX;
      } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
        TelephonyManager manager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        if (manager != null && manager.getSimState() == TelephonyManager.SIM_STATE_READY) {
          switch (manager.getNetworkType()) {

            // Unknown
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
              result = NetworkType.CELLULAR_UNKNOWN;
              break;
            // Cellular Data 2G
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_IDEN:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
              result = NetworkType.CELLULAR_2G;
              break;
            // Cellular Data 3G
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
              result = NetworkType.CELLULAR_3G;
              break;
            // Cellular Data 4G
            case TelephonyManager.NETWORK_TYPE_LTE:
              result = NetworkType.CELLULAR_4G;
              break;
            // Cellular Data Unknown Generation
            default:
              result = NetworkType.CELLULAR_UNIDENTIFIED_GEN;
              break;
          }
        }
      }
    }
  }
  return result;
}
 
Example 14
Source File: NetworkUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
@RequiresPermission(ACCESS_NETWORK_STATE)
public static NetworkType getNetworkType() {
    NetworkType netType = NetworkType.NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        if (info.getType() == ConnectivityManager.TYPE_ETHERNET) {
            netType = NetworkType.NETWORK_ETHERNET;
        } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            netType = NetworkType.NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {
                case TelephonyManager.NETWORK_TYPE_GSM:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    netType = NetworkType.NETWORK_2G;
                    break;
                case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    netType = NetworkType.NETWORK_3G;
                    break;
                case TelephonyManager.NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    netType = NetworkType.NETWORK_4G;
                    break;
                default:
                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NetworkType.NETWORK_3G;
                    } else {
                        netType = NetworkType.NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NetworkType.NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 15
Source File: PlayerUtils.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 判断当前网络类型
 */
public static int getNetworkType(Context context) {
    //改为context.getApplicationContext(),防止在Android 6.0上发生内存泄漏
    ConnectivityManager connectMgr = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectMgr == null) {
        return NO_NETWORK;
    }

    NetworkInfo networkInfo = connectMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        // 没有任何网络
        return NO_NETWORK;
    }
    if (!networkInfo.isConnected()) {
        // 网络断开或关闭
        return NETWORK_CLOSED;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
        // 以太网网络
        return NETWORK_ETHERNET;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        // wifi网络,当激活时,默认情况下,所有的数据流量将使用此连接
        return NETWORK_WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        // 移动数据连接,不能与连接共存,如果wifi打开,则自动关闭
        switch (networkInfo.getSubtype()) {
            // 2G
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_IDEN:
                // 3G
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
            case TelephonyManager.NETWORK_TYPE_EHRPD:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                // 4G
            case TelephonyManager.NETWORK_TYPE_LTE:
                // 5G
            case TelephonyManager.NETWORK_TYPE_NR:
                return NETWORK_MOBILE;
        }
    }
    // 未知网络
    return NETWORK_UNKNOWN;
}
 
Example 16
Source File: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the connection subtype for the given NetworkState.
 */
public int getConnectionSubtype() {
    if (!isConnected()) {
        return ConnectionSubtype.SUBTYPE_NONE;
    }

    switch (getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (getNetworkSubType()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return ConnectionSubtype.SUBTYPE_GPRS;
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return ConnectionSubtype.SUBTYPE_EDGE;
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return ConnectionSubtype.SUBTYPE_CDMA;
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return ConnectionSubtype.SUBTYPE_1XRTT;
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionSubtype.SUBTYPE_IDEN;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return ConnectionSubtype.SUBTYPE_UMTS;
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_0;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_A;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return ConnectionSubtype.SUBTYPE_HSDPA;
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return ConnectionSubtype.SUBTYPE_HSUPA;
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return ConnectionSubtype.SUBTYPE_HSPA;
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_B;
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return ConnectionSubtype.SUBTYPE_EHRPD;
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionSubtype.SUBTYPE_HSPAP;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionSubtype.SUBTYPE_LTE;
                default:
                    return ConnectionSubtype.SUBTYPE_UNKNOWN;
            }
        default:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
    }
}
 
Example 17
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 *
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            mIsAtLeast4G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            mIsAtLeast4G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
            }
    }
}
 
Example 18
Source File: AbstractNetworkUtils.java    From tenor-android-core with Apache License 2.0 4 votes vote down vote up
/**
 * Update batch size based on network type and status
 *
 * @param context the context, usually the application context
 */
public static int updateBatchSize(@Nullable final Context context) {
    if (context == null) {
        sBatchSize = 6;
        return sBatchSize;
    }

    // No network, use small batch size
    NetworkInfo info = getNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        sBatchSize = 6;
        return sBatchSize;
    }

    // In WiFi, use large batch size
    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
        sBatchSize = 24;
        return sBatchSize;
    }

    if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
        switch (info.getSubtype()) {
            case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
            case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
            case TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
                sBatchSize = 24;
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400 kbps
            case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
            case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
                sBatchSize = 12;
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
            case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                sBatchSize = 6;
                break;
        }
    } else {
        // In other undetermined network, use small batch size
        sBatchSize = 6;
    }
    return sBatchSize;
}
 
Example 19
Source File: NetworkUtils.java    From fangzhuishushenqi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 {@code <uses-permission android:name="android.permission
 * .ACCESS_NETWORK_STATE"/>}</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>{@link #NETWORK_WIFI   } = 1;</li>
 * <li>{@link #NETWORK_4G     } = 4;</li>
 * <li>{@link #NETWORK_3G     } = 3;</li>
 * <li>{@link #NETWORK_2G     } = 2;</li>
 * <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 * <li>{@link #NETWORK_NO     } = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            netType = NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {

                case NETWORK_TYPE_GSM:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    netType = NETWORK_2G;
                    break;

                case NETWORK_TYPE_TD_SCDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    netType = NETWORK_3G;
                    break;

                case NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    netType = NETWORK_4G;
                    break;
                default:

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 20
Source File: NetworkMonitorAutoDetect.java    From webrtc_android with MIT License 4 votes vote down vote up
private static ConnectionType getConnectionType(
    boolean isConnected, int networkType, int networkSubtype) {
  if (!isConnected) {
    return ConnectionType.CONNECTION_NONE;
  }

  switch (networkType) {
    case ConnectivityManager.TYPE_ETHERNET:
      return ConnectionType.CONNECTION_ETHERNET;
    case ConnectivityManager.TYPE_WIFI:
      return ConnectionType.CONNECTION_WIFI;
    case ConnectivityManager.TYPE_WIMAX:
      return ConnectionType.CONNECTION_4G;
    case ConnectivityManager.TYPE_BLUETOOTH:
      return ConnectionType.CONNECTION_BLUETOOTH;
    case ConnectivityManager.TYPE_MOBILE:
      // Use information from TelephonyManager to classify the connection.
      switch (networkSubtype) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
          return ConnectionType.CONNECTION_2G;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
          return ConnectionType.CONNECTION_3G;
        case TelephonyManager.NETWORK_TYPE_LTE:
          return ConnectionType.CONNECTION_4G;
        default:
          return ConnectionType.CONNECTION_UNKNOWN_CELLULAR;
      }
    case ConnectivityManager.TYPE_VPN:
      return ConnectionType.CONNECTION_VPN;
    default:
      return ConnectionType.CONNECTION_UNKNOWN;
  }
}