简体   繁体   中英

Android - Check if device supports 4G/LTE

How to determine if a android device supports 4G/LTE networks? Checking the current network type is not an option, because I have to check it even if the current network type is 3G.

UPDATE: OK, I have managed to detect the prefered_network_mode by: Settings.Secure.getInt(context.getContentResolver(), "preferred_network_mode", -1);

It work's fine on HTC One but on Samsung devices it always returns a 0 value when it should return more then a 0 value and that is the main problem now ;/

Does Samsung phones store the preferred network mode somewhere else ?

/**
 * 获取当前网络类型
 * 
 * @param context
 * @return 2G/3G/4G/WIFI/no/unknown
 */
public static String getNetType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null || !info.isAvailable()) {
        return "no";
    }
    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
        return "WIFI";
    }
    if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
        int sub = info.getSubtype();
        switch (sub) {

        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_CDMA://电信的2G
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            //以上的都是2G网络
            return "2G";

        case TelephonyManager.NETWORK_TYPE_UMTS:
        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:   
            //以上的都是3G网络
            return "3G";

        case TelephonyManager.NETWORK_TYPE_LTE:

            return "4G";

        case TelephonyManager.NETWORK_TYPE_UNKNOWN:

            return "unknown";

        default:
            return "unknown";
        }
    }
    return "unknown";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM