如何在Android应用程序中获得准确的信号强度?
How to get accurate signal strength in Android application?
我使用 CellInfo 来捕捉信号强度和 ARFCN/UARFCN/EARFCN 每秒。
但是,我觉得不是很准确。它总是比 Phone 设置中显示的信号强度差 -5 ~ -10 dBm。有时,我也得到 0 或 integer.MAX_VALUE。我的代码有问题吗?还有其他方法可以捕获真实信号强度吗?
var cellInfoList: List<CellInfo> = mTelephonyManager.allCellInfo
if (cellInfoList.isNotEmpty()) {
for (cellInfo in cellInfoList) {
if (cellInfo is CellInfoLte) {
val cellSignalStrengthLte = cellInfo.cellSignalStrength
val cellIdentityLte = cellInfo.cellIdentity
var arfcn = cellIdentityLte.earfcn
intSignalStrength = cellSignalStrengthLte.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoGsm) {
val cellSignalStrengthGsm = cellInfo.cellSignalStrength
val cellIdentityGsm = cellInfo.cellIdentity
var arfcn = cellIdentityGsm.arfcn
intSignalStrength = cellSignalStrengthGsm.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoWcdma) {
val cellSignalStrengthWcdma = cellInfo.cellSignalStrength
val cellIdentityWcdma = cellInfo.cellIdentity
var arfcn = uarfcnToBand(cellIdentityWcdma.uarfcn)
intSignalStrength = cellSignalStrengthWcdma.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoCdma) {
val cellSignalStrengthCdma = cellInfo.cellSignalStrength
intSignalStrength = cellSignalStrengthCdma.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm"
}
}
}
我得到了解决方案。问题出在for循环。最新的信号强度是第一个循环所以下面的循环将覆盖我需要的结果。
我使用 CellInfo 来捕捉信号强度和 ARFCN/UARFCN/EARFCN 每秒。
但是,我觉得不是很准确。它总是比 Phone 设置中显示的信号强度差 -5 ~ -10 dBm。有时,我也得到 0 或 integer.MAX_VALUE。我的代码有问题吗?还有其他方法可以捕获真实信号强度吗?
var cellInfoList: List<CellInfo> = mTelephonyManager.allCellInfo
if (cellInfoList.isNotEmpty()) {
for (cellInfo in cellInfoList) {
if (cellInfo is CellInfoLte) {
val cellSignalStrengthLte = cellInfo.cellSignalStrength
val cellIdentityLte = cellInfo.cellIdentity
var arfcn = cellIdentityLte.earfcn
intSignalStrength = cellSignalStrengthLte.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoGsm) {
val cellSignalStrengthGsm = cellInfo.cellSignalStrength
val cellIdentityGsm = cellInfo.cellIdentity
var arfcn = cellIdentityGsm.arfcn
intSignalStrength = cellSignalStrengthGsm.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoWcdma) {
val cellSignalStrengthWcdma = cellInfo.cellSignalStrength
val cellIdentityWcdma = cellInfo.cellIdentity
var arfcn = uarfcnToBand(cellIdentityWcdma.uarfcn)
intSignalStrength = cellSignalStrengthWcdma.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm | $arfcn"
} else if (cellInfo is CellInfoCdma) {
val cellSignalStrengthCdma = cellInfo.cellSignalStrength
intSignalStrength = cellSignalStrengthCdma.dbm
networkStatus = "${Integer.toString(intSignalStrength)} dBm"
}
}
}
我得到了解决方案。问题出在for循环。最新的信号强度是第一个循环所以下面的循环将覆盖我需要的结果。