0

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 ?

Michal
  • 1
  • 1
  • 3
  • Check out : http://stackoverflow.com/questions/2802472/detect-network-connection-type-on-android – Haresh Chhelana May 13 '15 at 10:05
  • this too: http://stackoverflow.com/questions/9283765/how-to-determine-if-network-type-is-2g-3g-or-4g?lq=1 – Behnam May 13 '15 at 10:31
  • Thanks for a reply, but checking the current network type is not an option, because I have to check the 4G-LTE capabilitz even if the current network type is 3G. – Michal May 13 '15 at 10:53

1 Answers1

0
/**
 * 获取当前网络类型
 * 
 * @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";
}
cheyiliu
  • 1
  • 1