Skip to content Skip to sidebar Skip to footer

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 statu

Solution 1:

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

staticbooleanisNRConnected(TelephonyManager telephonyManager) {
    try {
        Object obj = Class.forName(telephonyManager.getClass().getName())
                .getDeclaredMethod("getServiceState", newClass[0]).invoke(telephonyManager, newObject[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, newObject[0])).intValue() == 3;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    returnfalse;
}

Solution 2:

There is an official documentation to detect 5G on Android 11. https://developer.android.com/about/versions/11/features/5g#detection

Call TelephonyManager.listen(), passing in LISTEN_DISPLAY_INFO_CHANGED, to determine if the user has a 5G network connection.

Solution 3:

as @Hunter suggested you need to use "listen" from telephony manager but if it's api 30+ you need to have READ_PHONE permission granted and listen for LISTEN_DISPLAY_INFO_CHANGED and override onDisplayInfoChanged from PhoneStateListener

(context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).listen(customPhoneStateListener,PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED)

The listener should be something like this:

privateclassCustomPhoneStateListener : PhoneStateListener() {
    overridefunonDisplayInfoChanged(telephonyDisplayInfo: TelephonyDisplayInfo) {
               
                super.onDisplayInfoChanged(telephonyDisplayInfo)
              
                    when (telephonyDisplayInfo.overrideNetworkType) {
                         //5G
                        OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO,
                        OVERRIDE_NETWORK_TYPE_NR_NSA,
                        OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> setNetworkChange(NETWORK_TYPE_NR)
                        OVERRIDE_NETWORK_TYPE_LTE_CA -> {
                            setNetworkChange(19) //LTE+
                        }
                        else -> setNetworkChange(telephonyDisplayInfo.networkType)
                    }
                } else {
                    setNetworkChange(telephonyDisplayInfo.networkType)
                }
            }

   }

Link: https://developer.android.com/about/versions/11/features/5g#detection

Solution 4:

Couldn't add this as a comment, but as @Pavel Machala said, looking at the ServiceState class in the AOSP yields the following:

/**
 * Get the NR 5G status of the mobile data network.
 * @return the NR 5G status.
 * @hide
 */public@NRStatusintgetNrStatus() {
    finalNetworkRegistrationStateregState= getNetworkRegistrationState(
            NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
    if (regState == null) return NetworkRegistrationState.NR_STATUS_NONE;
    return regState.getNrStatus();
}

Solution 5:

I have extracted the ServiceState.java from SM-G977N firmware and it confirms that they have added ServiceState.getNrStatus()

5G(NR) is active is if NetworkRegistrationState.NR_STATUS_CONNECTED = 3;

Post a Comment for "How To Detect Samsung S10 5g Is Running On 5g Network?"