在看到那个问题和答案之后(顺便谢谢),我写了这段代码,它与答案中的几乎相同:
try {
List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
for (CellInfo cellInfo : cellInfoList) {
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
CellIdentityGsm cellIdentity = cellInfoGsm.getCellIdentity();
final CellSignalStrengthGsm gsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
rsrpValue = gsm.getDbm();
pciValue = cellIdentity.getCid();
} else if (cellInfo instanceof CellInfoCdma) {
CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfo;
CellIdentityCdma cellIdentity = cellInfoCdma.getCellIdentity();
pciValue = cellIdentity.getBasestationId();
} else if (cellInfo instanceof CellInfoLte){
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
CellIdentityLte cellIdentity = cellInfoLte.getCellIdentity();
pciValue = cellIdentity.getPci();
} else {
throw new Exception("Unknown type of cell signal!");
}
}
} catch (Exception e) {
Log.e(TAG, "Unable to obtain cell signal information", e);
}
但是当我为 GSM 显示 rsrpValue 或 pciValue 时,我总是得到最大整数值(2147483647)。我在带有 API 17 的手机上尝试了这个。我的代码有问题吗?
谢谢