Android: 无法获取 LTE CellId

Android: Can't get LTE CellId

我正在尝试在我的应用程序中获取 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(); 总是 return 2147483647,最大值表明有问题。

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

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

这是一个修复方法:

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