首先,这是我获取 lte rsrp(或其他)值的代码。此代码段在另一个 aysncTask 上运行。
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int tempInt;
while (isRunning) {
try {
List<CellInfo> cellInfoList = tm.getAllCellInfo();
if (cellInfoList != null && cellInfoList.size() != 0) {
msg = handler.obtainMessage();
CellInfo cellInfo = cellInfoList.get(0);
result = -9999;
tempInt = 0;
if (cellInfo instanceof CellInfoWcdma) {
result = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm();
Log.e(TAG, "3G : " + result + "");
} else if (cellInfo instanceof CellInfoLte) {
result = ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();
Log.e(TAG, "LTE : " + result);
} else if (cellInfo instanceof CellInfoGsm) {
result = ((CellInfoGsm) cellInfo).getCellSignalStrength().getDbm();
Log.e(TAG, "GSM" + result);
} else if (cellInfo instanceof CellInfoCdma) {
result = ((CellInfoCdma) cellInfo).getCellSignalStrength().getDbm();
Log.e(TAG, "CDMA" + result);
}
.....
问题是,我不确定我得到的数据是否正确。
当我让这个源在后台运行以查看 rsrp 值时,我使用命令 *123456# 运行 LG G3 的隐藏菜单。它显示了显示实时 rsrp 值的调试模式。
问题是,在大多数情况下,我在应用程序日志中获得的 rsrp 和隐藏菜单上的 rsrp 是不同的。我的应用显示大约 -3 ~ +3 更多。
为什么会这样?我的代码有问题吗?上面的代码没有时间间隔,在我强制关闭应用程序之前会继续。