Java Code Examples for android.telephony.TelephonyManager#NETWORK_TYPE_NR

The following examples show how to use android.telephony.TelephonyManager#NETWORK_TYPE_NR . 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: NetWorkUtils.java    From DevUtils with Apache License 2.0 7 votes vote down vote up
/**
 * 获取移动网络连接类型
 * <pre>
 *     {@link TelephonyManager#getNetworkClass} hide 方法
 * </pre>
 * @param networkType {@link TelephonyManager#getNetworkType}
 * @return 0 = 未知, 1 = 2G, 2 = 3G, 3 = 4G, 4 = 5G
 */
public static int getNetworkClass(final int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return 1;
        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:
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
            return 2;
        case TelephonyManager.NETWORK_TYPE_LTE:
        case TelephonyManager.NETWORK_TYPE_IWLAN:
        case 19: // TelephonyManager.NETWORK_TYPE_LTE_CA
            return 3;
        case TelephonyManager.NETWORK_TYPE_NR:
            return 4;
        default:
            return 0;
    }
}
 
Example 2
Source File: NetworkUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether using 4G.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean is5G() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null
            && info.isAvailable()
            && info.getSubtype() == TelephonyManager.NETWORK_TYPE_NR;
}
 
Example 3
Source File: NetworkTypeUtils.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public static NetworkGroup getNetworkGroup(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return NetworkGroup.Gsm;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return NetworkGroup.Wcdma;
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return NetworkGroup.Cdma;
        case TelephonyManager.NETWORK_TYPE_LTE:
            return NetworkGroup.Lte;
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
            return NetworkGroup.Tdscdma;
        case TelephonyManager.NETWORK_TYPE_NR:
            return NetworkGroup.Nr;
        case TelephonyManager.NETWORK_TYPE_IDEN:
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        case TelephonyManager.NETWORK_TYPE_IWLAN:
        default:
            return NetworkGroup.Unknown;
    }
}
 
Example 4
Source File: chat_command_service.java    From telegram-sms with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private String check_cellular_network_type(int type, boolean is_att) {
    String net_type = "Unknown";
    switch (type) {
        case TelephonyManager.NETWORK_TYPE_NR:
            net_type = "5G";
            if (is_att) {
                net_type = "5G+";
            }
            break;
        case TelephonyManager.NETWORK_TYPE_LTE:
            net_type = "LTE";
            if (is_att) {
                net_type = "5G E";
            }
            break;
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            if (is_att) {
                net_type = "4G";
                break;
            }
        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_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            net_type = "3G";
            break;
        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:
            net_type = "2G";
            break;
    }
    return net_type;
}
 
Example 5
Source File: VenvyDeviceUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static int getNetWorkType(Context context) {
    int strNetworkType = 0;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
            (Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            strNetworkType = 1;
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            String _strSubTypeName = networkInfo.getSubtypeName();
            VenvyLog.i("cocos2d-x", "Network getSubtypeName : " + _strSubTypeName);

            // TD-SCDMA   networkType is 17
            int networkType = networkInfo.getSubtype();
            switch (networkType) {
                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: //api<8 : replace by 11
                case TelephonyManager.NETWORK_TYPE_GSM:  // api<25: replace by 16
                    strNetworkType = 2;
                    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:   // api< 9: replace by 12
                case TelephonyManager.NETWORK_TYPE_EHRPD:    // api<11: replace by 14
                case TelephonyManager.NETWORK_TYPE_HSPAP:    // api<13: replace by 15
                case TelephonyManager.NETWORK_TYPE_TD_SCDMA: // api<25: replace by 17
                    strNetworkType = 3;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE:      // api<11: replace by 13
                case TelephonyManager.NETWORK_TYPE_IWLAN:    // api<25: replace by 18
                    strNetworkType = 4;
                    break;
                case TelephonyManager.NETWORK_TYPE_NR:// api<29: replace by 20
                    strNetworkType = 5;
                    break;
            }
        }
    }
    return strNetworkType;
}
 
Example 6
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 7
Source File: NetworkUtils.java    From AndroidUtilCode with Apache License 2.0 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_ETHERNET} </li>
 * <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() {
    if (isEthernet()) {
        return NetworkType.NETWORK_ETHERNET;
    }
    NetworkInfo info = getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return 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:
                    return NetworkType.NETWORK_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 NetworkType.NETWORK_3G;

                case TelephonyManager.NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetworkType.NETWORK_4G;

                case TelephonyManager.NETWORK_TYPE_NR:
                    return NetworkType.NETWORK_5G;
                default:
                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        return NetworkType.NETWORK_3G;
                    } else {
                        return NetworkType.NETWORK_UNKNOWN;
                    }
            }
        } else {
            return NetworkType.NETWORK_UNKNOWN;
        }
    }
    return NetworkType.NETWORK_NO;
}