gpt4 book ai didi

java - 使用 CellSignalStrengthGsm 只给出 Integer.MAX_VALUE

转载 作者:太空狗 更新时间:2023-10-29 14:17:55 26 4
gpt4 key购买 nike

看到question之后以及答案(顺便说一句,谢谢)我写的这段代码与答案中的代码几乎相同:

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 的手机上试过这个。我的代码有什么问题吗?

谢谢

最佳答案

尝试使用旧的 PhoneStateListener 来监听信号强度变化。这对我有用。使用它来注册监听器:

private TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int currentSignalStrength = 0;
int asu = 0;

telManager.listen(new SignalStrengthListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

这是真正的听众:

private class SignalStrengthListener extends PhoneStateListener{

@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
if (telManager.getPhoneType()== TelephonyManager.PHONE_TYPE_CDMA)
currentSignalStrength = signalStrength.getCdmaDbm();
else
asu = signalStrength.getGsmSignalStrength();
}
}

在 Xperia Z 上测试,使用 CellInfoGsm 也有同样的问题。

关于java - 使用 CellSignalStrengthGsm 只给出 Integer.MAX_VALUE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19840487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com