【问题标题】:Android: Can't get LTE CellIdAndroid:无法获取 LTE CellId
【发布时间】:2021-04-20 15:03:35
【问题描述】:

我正在尝试在我的应用中获取 LTE 小区 ID 号:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfoList = tm.getAllCellInfo();

for (CellInfo cellInfo : cellInfoList)
    {
    if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdentityLte = ((CellInfoLte) cellInfo).getCellIdentity();
        cellID = cellIdentityLte.getCi();
    }
}

但是cellID = cellIdentityLte.getCi(); 总是返回 2147483647,最大值表明有问题。

我猜权限 ACCESS_FINE_LOCATION 和 READ_PHONE_STATE 就足够了。 Play 商店中的其他应用程序为我提供了正确的 cellID,因此设备不是问题(并在多部手机上进行了测试)。 顺便运行 SDK v.30。

【问题讨论】:

    标签: java android telephonymanager


    【解决方案1】:

    在 for 循环中获取值时,还会迭代相邻小区,这些小区的 cid 为空,因为 UE 未连接到它们。

    这是一个修复:

    if (cellIdentityLte.getCi() != 0 && cellIdentityLte.getCi() != 2147483647) 
    {
       cellID = cellIdentityLte.getCi();
    }
    

    【讨论】:

    • 我会使用Integer.MAX_VALUE 进行比较。
    猜你喜欢
    • 1970-01-01
    • 2015-06-14
    • 2015-10-02
    • 2011-11-05
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多