The phone show me 5G, but telephoneManager.getDataNetworkType is LTE. In the settings, the sim card State show me the Mobile Voice Network Type(translate from Chinese, maybe not correct) is NR NSA (non standalone), but the Mobile data network type (translate from Chinese) is LTE.
So, how can I judge the 5G NSA or SA (standalone)?
I'm a new hand in Android, I'm not good at English, hhhh...thank you. That's my first question in Stackoverflow.
In case you may have an Android 11 device, please refer to: https://source.android.com/devices/tech/connect/acts-5g-testing https://developer.android.com/about/versions/11/features/5g#detection
The emulator
would also support faking a 5G network connection since 30.0.22:
https://developer.android.com/about/versions/11/behavior-changes-all#emulator-5g
TelephonyManager
and TelephonyDisplayInfo
are both required for proper detection:
SL4A uses the following values to distinguish between NSA (non standalone), mmWave (millimeter wave) and SA (standalone) connection types for 5G:
Type
Values
5G NSA
TelephonyManager.getDataNetworkType() = LTE
TelephonyDisplayInfo.getNetworkType() = LTE
TelephonyDisplayInfo.getOverrideNetworkType() = NR_NSA
5G mmWave
TelephonyDisplayInfo.getOverrideNetworkType() = NR_MMWAVE
5G SA
TelephonyManager.getDataNetworkType() = NR
TelephonyDisplayInfo.getNetworkType() = NR
TelephonyDisplayInfo.getOverrideNetworkType()
can be used to tell apart 4G LTE from 5G NSA. While in most areas, an Android 11 emulator
might be the best chance to actually test this.
Unfortunately, you can't rely on the APIs for many of these cases.
The only method I found is to register a listener to get the ServiceState
from the TelephonyManager and then parse the result of serviceState.toString()
telephonyManager.listen(object : PhoneStateListener() {
override fun onServiceStateChanged(state: ServiceState) {
val serviceState = state.toString()
val nr = serviceState.isNrAvailable()
...
}
}, PhoneStateListener.LISTEN_SERVICE_STATE)
fun String.isNrAvailable() =
contains("nrState=CONNECTED") ||
contains("nsaState=5"))
This gives you the correct answer most
of the times. BTW NR NSA
is the correct name for NR non-standalone.
If you want to distinguish between NRSA and NRNSA you need to fetch all the cellInfo from the TelephonyManager
telephonyManager.allCellInfo
and check whether the primary cell is NR.
cellInfo.cellConnectionStatus
In some cases what you will see is that there are no NR cells. In that case, you can be sure that the connection is NRNSA (assuming that it is 5G). In other cases, there will be NR cells but they won't be reported as primary-cell. It is possible that the device will even report the NR cell as not connected at all even if it is used. Again in that case you know it is NRNSA. You might detect the NR cell that is used even if it is reported as not connected by checking the strengths.
cellInfo.cellSignalStrength.dbm
You will see that the strength reported is the same as the strength of the NR cell with the highest SS-RSRP (Synchronization Signal Reference Signal Received Power)
I would avoid using the TelephonyDisplayInfo
since it is not reliable. These values are shown to the users and they follow the carrier policy or brand preferences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With