Java Code Examples for android.telephony.TelephonyManager#NETWORK_TYPE_UMTS

The following examples show how to use android.telephony.TelephonyManager#NETWORK_TYPE_UMTS . 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: CellTower.java    From satstat with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the network generation of a phone network type.
 * @param networkType The network type as returned by {@link TelephonyManager.getNetworkType}
    * @return 2, 3 or 4 for 2G, 3G or 4G; 0 for unknown
 */
public static int getGenerationFromNetworkType(int networkType) {
	switch (networkType) {
	case TelephonyManager.NETWORK_TYPE_CDMA:
	case TelephonyManager.NETWORK_TYPE_EDGE:
	case TelephonyManager.NETWORK_TYPE_GPRS:
	case TelephonyManager.NETWORK_TYPE_IDEN:
		return 2;
	case TelephonyManager.NETWORK_TYPE_1xRTT:
	case TelephonyManager.NETWORK_TYPE_EHRPD:
	case TelephonyManager.NETWORK_TYPE_EVDO_0:
	case TelephonyManager.NETWORK_TYPE_EVDO_A:
	case TelephonyManager.NETWORK_TYPE_EVDO_B:
	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 3;
	case TelephonyManager.NETWORK_TYPE_LTE:
		return 4;
	default:
		return 0;
	}
}
 
Example 2
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 3
Source File: NetInfoModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
private String getEffectiveConnectionType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    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:
      return EFFECTIVE_CONNECTION_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_UMTS:
      return EFFECTIVE_CONNECTION_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_LTE:
      return EFFECTIVE_CONNECTION_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default:
      return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
  }
}
 
Example 4
Source File: Util.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_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:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 5
Source File: NetworkUtil.java    From RetrofitClient with Apache License 2.0 5 votes vote down vote up
/**
 *  is wifi on
 */
public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mgrTel = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
            .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
            .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
 
Example 6
Source File: RxNetTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 判断WIFI是否打开
 */
public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mgrTel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return ((mgrConn.getActiveNetworkInfo() != null
            && mgrConn.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
            || mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
 
Example 7
Source File: NetworkUtil.java    From MvpRxJavaRetrofitOkhttp with MIT License 5 votes vote down vote up
/**
 * check is wifi on
 */
public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mgrTel = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
            .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
            .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
 
Example 8
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 9
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 10
Source File: DataIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
private void onDataChanged() {
    switch (telephonyManager.getDataState()) {
        case TelephonyManager.DATA_CONNECTED:
        case TelephonyManager.DATA_CONNECTING:
            if (telephonyManager.getDataState() != TelephonyManager.DATA_DISCONNECTED) {
                switch (telephonyManager.getNetworkType()) {
                    case TelephonyManager.NETWORK_TYPE_GPRS:
                    case TelephonyManager.NETWORK_TYPE_EDGE:
                    case TelephonyManager.NETWORK_TYPE_IDEN:
                        onTextUpdate("2G");
                        return;
                    case TelephonyManager.NETWORK_TYPE_UMTS:
                    case TelephonyManager.NETWORK_TYPE_HSDPA:
                    case TelephonyManager.NETWORK_TYPE_HSUPA:
                    case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    case TelephonyManager.NETWORK_TYPE_EHRPD:
                    case TelephonyManager.NETWORK_TYPE_CDMA:
                    case TelephonyManager.NETWORK_TYPE_1xRTT:
                        onTextUpdate("3G");
                        return;
                    case TelephonyManager.NETWORK_TYPE_HSPA:
                        onTextUpdate("H");
                        return;
                    case TelephonyManager.NETWORK_TYPE_HSPAP:
                        onTextUpdate("H+");
                        return;
                    case TelephonyManager.NETWORK_TYPE_LTE:
                        onTextUpdate("4G");
                        return;
                }
            }
    }

    onTextUpdate(null);
}
 
Example 11
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_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:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 12
Source File: NetworkUtil.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**<br/>
 * http://www.binkery.com/post/368.html<br/>*/
private static boolean isSlowMobileNetwork(Context context){
	TelephonyManager telephonyManager = (TelephonyManager) context
			.getSystemService(Context.TELEPHONY_SERVICE);
	boolean result=true;
	if(telephonyManager!=null){
		switch(telephonyManager.getNetworkType()){
			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:
				result=true;//2g
				break;
			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:
				result=false;//3g
				break;
			case TelephonyManager.NETWORK_TYPE_LTE:
				result=false;//4g
				break;
			case TelephonyManager.NETWORK_TYPE_UNKNOWN:
				result=true;
				break;
		}
	}else{
		result=true;
	}
	return result;
}
 
Example 13
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 14
Source File: NetworkUtils.java    From MyUtil with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络状态
 * @param context 全局context
 * @return
 * 没有网络-NO
 * WIFI网络-WIFI
 * 4G网络-4G
 * 3G网络-3G
 * 2G网络-2G
 * 未知-Unknown
 */
public static String getAPNType(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {      //无网络
        return "NO";
    }

    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_WIFI) {       //wifi
        return "WIFI";
    } else if (nType == ConnectivityManager.TYPE_MOBILE) {
        int nSubType = networkInfo.getSubtype();
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (nSubType == TelephonyManager.NETWORK_TYPE_LTE
                && !telephonyManager.isNetworkRoaming()) {
            return "4G";
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_A
                || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
                || nSubType == TelephonyManager.NETWORK_TYPE_HSUPA
                || nSubType == TelephonyManager.NETWORK_TYPE_HSPA
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_B
                || nSubType == TelephonyManager.NETWORK_TYPE_EHRPD
                || nSubType == TelephonyManager.NETWORK_TYPE_HSPAP
                && !telephonyManager.isNetworkRoaming()) {
            return "3G";
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS
                || nSubType == TelephonyManager.NETWORK_TYPE_EDGE
                || nSubType == TelephonyManager.NETWORK_TYPE_CDMA
                || nSubType == TelephonyManager.NETWORK_TYPE_1xRTT
                || nSubType == TelephonyManager.NETWORK_TYPE_IDEN
                && !telephonyManager.isNetworkRoaming()) {
            return "2G";
        } else {
            return "Unknown";
        }
    }

    return "Unknown";
}
 
Example 15
Source File: NetworkUtil.java    From RxZhihuDaily with MIT License 4 votes vote down vote up
/**
 * 仅判断Mobile网络的慢速.蓝牙等其他网络不做判断.
 *
 * @param context
 * @return
 */
public static NetworkSpeedMode getNetworkSpeedModeInMobile(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) {
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null) {
            if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                switch (networkInfo.getSubtype()) {
                    case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
                        return NetworkSpeedMode.LOW;
                    case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
                        return NetworkSpeedMode.LOW;
                    case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
                        return NetworkSpeedMode.LOW;
                    case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
                        return NetworkSpeedMode.LOW;
                    case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
                        return NetworkSpeedMode.LOW;

                    case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000
                        // kbps
                        return NetworkSpeedMode.NORMAL;
                    case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400
                        // kbps
                        return NetworkSpeedMode.NORMAL;
                    case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
                        return NetworkSpeedMode.NORMAL;
                    case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
                        return NetworkSpeedMode.NORMAL;
                    case 14: // TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2
                        // Mbps
                        return NetworkSpeedMode.NORMAL;
                    case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5
                        // Mbps
                        return NetworkSpeedMode.NORMAL;

                    case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
                        return NetworkSpeedMode.HIGH;
                    case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
                        return NetworkSpeedMode.HIGH;
                    case 15: // TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20
                        // Mbps
                        return NetworkSpeedMode.HIGH;
                    case 13: // TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
                        return NetworkSpeedMode.HIGH;

                    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                        return NetworkSpeedMode.NORMAL;
                    default:
                        break;
                }
            }
        }
    }
    return NetworkSpeedMode.UNKNOWN;
}
 
Example 16
Source File: CellTowerListGsm.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, its data is updated; if not, a
 * new entry is created. Cells whose network type is not a flavor of GSM or
 * UMTS will be rejected.
 * <p>
 * This method will set the cell's identity data, generation and its signal
 * strength. 
 * @return The new or updated entry, or {@code null} if the cell was rejected
 */
public CellTowerGsm update(String networkOperator, NeighboringCellInfo cell) {
	int mcc = CellTower.UNKNOWN;
	int mnc = CellTower.UNKNOWN;
	if (networkOperator.length() > 3) {
		mcc = Integer.parseInt(networkOperator.substring(0, 3));
		mnc = Integer.parseInt(networkOperator.substring(3));
	}
	CellTowerGsm result = null;
	CellTowerGsm cand = this.get(mcc, mnc, cell.getLac(), cell.getCid());
	if ((cand != null) && CellTower.matches(cell.getPsc(), cand.getPsc()))
		result = cand;

	if (result == null) {
		cand = this.get(cell.getPsc());
		if ((cand != null)
				&& CellTower.matches(mcc, cand.getMcc())
				&& CellTower.matches(mnc, cand.getMnc())
				&& CellTower.matches(cell.getLac(), cand.getLac())
				&& CellTower.matches(cell.getCid(), cand.getCid()))
			result = cand;
	}
	if (result == null)
		result = new CellTowerGsm(mcc, mnc, cell.getLac(), cell.getCid(), cell.getPsc());
	result.setNeighboringCellInfo(true);
	int networkType = cell.getNetworkType();
	switch (networkType) {
		case TelephonyManager.NETWORK_TYPE_UMTS:
		case TelephonyManager.NETWORK_TYPE_HSDPA:
		case TelephonyManager.NETWORK_TYPE_HSUPA:
		case TelephonyManager.NETWORK_TYPE_HSPA:
			/*
			 * for details see TS 25.133 section 9.1.1.3
			 * http://www.3gpp.org/DynaReport/25133.htm
			 */
			result.setCpichRscp(cell.getRssi());
			break;
		case TelephonyManager.NETWORK_TYPE_EDGE:
		case TelephonyManager.NETWORK_TYPE_GPRS:
			result.setAsu(cell.getRssi());
			break;
		default:
			// not a GSM or UMTS cell, return
			return null;
			// result.setDbm(CellTower.DBM_UNKNOWN);
			// not needed because this is the default value; setting it
			// here might overwrite valid data obtained from a different
			// source
	}
	result.setNetworkType(networkType);
	if (result.getMcc() == CellTower.UNKNOWN)
		result.setMcc(mcc);
	if (result.getMnc() == CellTower.UNKNOWN)
		result.setMnc(mnc);
	if (result.getLac() == CellTower.UNKNOWN)
		result.setLac(cell.getLac());
	if (result.getCid() == CellTower.UNKNOWN)
		result.setCid(cell.getCid());
	if (result.getPsc() == CellTower.UNKNOWN)
		result.setPsc(cell.getPsc());
	this.put(result.getText(), result);
	this.put(result.getAltText(), result);
	if ((result.getText() == null) && (result.getAltText() == null))
		Log.d(this.getClass().getSimpleName(), String.format("Added %d G cell with no data from NeighboringCellInfo", result.getGeneration()));
	return result;
}
 
Example 17
Source File: NetworkChangeNotifierAutoDetect.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public int getCurrentConnectionType() {
    // Track exactly what type of connection we have.
    if (!mConnectivityManagerDelegate.activeNetworkExists() ||
            !mConnectivityManagerDelegate.isConnected()) {
        return NetworkChangeNotifier.CONNECTION_NONE;
    }

    switch (mConnectivityManagerDelegate.getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
            return NetworkChangeNotifier.CONNECTION_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return NetworkChangeNotifier.CONNECTION_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return NetworkChangeNotifier.CONNECTION_4G;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (mConnectivityManagerDelegate.getNetworkSubtype()) {
                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 NetworkChangeNotifier.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 NetworkChangeNotifier.CONNECTION_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetworkChangeNotifier.CONNECTION_4G;
                default:
                    return NetworkChangeNotifier.CONNECTION_UNKNOWN;
            }
        default:
            return NetworkChangeNotifier.CONNECTION_UNKNOWN;
    }
}
 
Example 18
Source File: NeihanManager.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
private String getNetworkType() {

        NetworkInfo info = ((ConnectivityManager) mNeihanPreference.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (info != null && info.isAvailable()) {
            if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                return "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:
                        return "2g";
                    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:
                        return "3g";
                    case TelephonyManager.NETWORK_TYPE_IWLAN:
                    case TelephonyManager.NETWORK_TYPE_LTE:
                        return "4g";
                    default:
                        String subtypeName = info.getSubtypeName();
                        if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                                || subtypeName.equalsIgnoreCase("WCDMA")
                                || subtypeName.equalsIgnoreCase("CDMA2000")) {
                            return "3g";
                        } else {
                            return "wifi";
                        }
                }
            } else {
                return "wifi";
            }
        }
        return "wifi";
    }
 
Example 19
Source File: LDNetUtil.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
private static String mobileNetworkType(Context context) {
  TelephonyManager telephonyManager = (TelephonyManager) context
      .getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null) {
    return "TM==null";
  }
  switch (telephonyManager.getNetworkType()) {
  case TelephonyManager.NETWORK_TYPE_1xRTT:// ~ 50-100 kbps
    return "2G";
  case TelephonyManager.NETWORK_TYPE_CDMA:// ~ 14-64 kbps
    return "2G";
  case TelephonyManager.NETWORK_TYPE_EDGE:// ~ 50-100 kbps
    return "2G";
  case TelephonyManager.NETWORK_TYPE_EVDO_0:// ~ 400-1000 kbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_EVDO_A:// ~ 600-1400 kbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_GPRS:// ~ 100 kbps
    return "2G";
  case TelephonyManager.NETWORK_TYPE_HSDPA:// ~ 2-14 Mbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_HSPA:// ~ 700-1700 kbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_UMTS:// ~ 400-7000 kbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_EHRPD:// ~ 1-2 Mbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_HSPAP:// ~ 10-20 Mbps
    return "3G";
  case TelephonyManager.NETWORK_TYPE_IDEN:// ~25 kbps
    return "2G";
  case TelephonyManager.NETWORK_TYPE_LTE:// ~ 10+ Mbps
    return "4G";
  case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    return "UNKNOWN";
  default:
    return "4G";
  }
}
 
Example 20
Source File: NetWorkUtils.java    From GankGirl with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Whether is fast mobile network
 *
 * @param context context
 * @return FastMobileNetwork
 */
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;
    }
}