androidandroid-networkingtelephonytelecommunication

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


Android Q added a new network type, NETWORK_TYPE_NR for 5G which is not available for Android Pie. Recently released Samsung S10 fully supports 5G. It can show 5G icon on the status bar when it is on the 5G network.

Is it possible for a third-party app to know if Android Pie device on a 5G network or not?

Any help will be appreciated.

The following link is the definition for the new network type. It is not available on the Android Pie branch.


Solution

  • 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;
    }