1 year ago
#270090
Ricky Mo
Android PhoneStateListener.LISTEN_SIGNAL_STRENGTHS and TelephonyManager#requestCellInfoUpdate return different signal strength
I want to monitor the cellular signal strength. My testing device use WCDMA.
telephonyManager.requestCellInfoUpdate(mainExecutor,object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(allCellInfo: MutableList<CellInfo>) {
allCellInfo.forEach {
val s = (it as CellInfoWcdma).cellSignalStrength
Log.d("requestCellInfoUpdate","ASU=${s.asuLevel}, dBm=${s.dbm}, level=${s.level}")
}
}
})
Gives requestCellInfoUpdate: ASU=96, dBm=-24, level=4
Looks fine, but I want to monitor the change. So I set up a PhoneStateListener
(My device is Android 11, so no registerTelephonyCallback
yet)
private val phoneStateListener : PhoneStateListener? = object: PhoneStateListener(){
override fun onSignalStrengthsChanged(signalStrength: SignalStrength?) {
super.onSignalStrengthsChanged(signalStrength)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
signalStrength?.cellSignalStrengths?.forEach {
val s = it as CellSignalStrengthWcdma
Log.d("onSignalStrengthsChanged","ASU=${s.asuLevel}, dBm=${s.dbm}, level=${s.level}")
}
}
}
}
telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS)
which gives me onSignalStrengthsChanged: ASU=55, dBm=-65, level=4
instead
It seems that the value obtained by PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
is wrong, is it? Do I have to call requestCellInfoUpdate
within onSignalStrengthsChanged
to get the true signal strength?
It also seems that the ASU level get by requestCellInfoUpdate
never update. If I put the phone in a microwave,
requestCellInfoUpdate
gives ASU=96, dBm=-24, level=1
while
onSignalStrengthsChanged
gives ASU=23, dBm=-97, level=2
.
I have no idea which value is right.
android
kotlin
telephonymanager
cellular-network
0 Answers
Your Answer