How to detect Samsung S10 5G is running on 5G network?

前端 未结 5 782
一整个雨季
一整个雨季 2021-01-07 01:24

Android Q added a new network type, NETWORK_TYPE_NR, for 5G, it is not available for Android Pie. Yet the just released Samsung S10 5G has fully supported 5G function, it ca

5条回答
  •  时光取名叫无心
    2021-01-07 01:46

    I believe they backported the code from Q to Pie as the logic for 5G was implemented at the end of last year in Q (alpha). So when using TelephonyManager.getNetworkType()

    you will likely get

    20 (5G)

    EDIT

    As per comment below: The network type will be 13 so it doesn't solve the thing.

    EDIT

    Try using reflection

    static boolean isNRConnected(TelephonyManager telephonyManager) {
        try {
            Object obj = Class.forName(telephonyManager.getClass().getName())
                    .getDeclaredMethod("getServiceState", new Class[0]).invoke(telephonyManager, new Object[0]);
    
            Method[] methods = Class.forName(obj.getClass().getName()).getDeclaredMethods();
    
            for (Method method : methods) {
                if (method.getName().equals("getNrStatus") || method.getName().equals("getNrState")) {
                    method.setAccessible(true);
                    return ((Integer) method.invoke(obj, new Object[0])).intValue() == 3;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    

提交回复
热议问题