简体   繁体   English

Android:无法获取 LTE CellId

[英]Android: Can't get LTE CellId

I am trying to get the LTE cell ID number in my app:我正在尝试在我的应用程序中获取 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();
    }
}

But cellID = cellIdentityLte.getCi();但是cellID = cellIdentityLte.getCi(); Always return 2147483647, the max values telling that something is wrong.总是返回 2147483647,最大值表明有问题。

I guess the permissions ACCESS_FINE_LOCATION and READ_PHONE_STATE are enough.我猜权限 ACCESS_FINE_LOCATION 和 READ_PHONE_STATE 就足够了。 Other app on the play store are giving me the correct cellID, so the device is not the issue (and tested on several phones). Play 商店中的其他应用程序为我提供了正确的 cellID,因此设备不是问题(并在多部手机上进行了测试)。 Running SDK v.30 by the way.顺便运行 SDK v.30。

When fetching the value in a for loop, neighbors cells are also iterated, which have a null cid because the UE is not attached to them.当在 for 循环中获取值时,也会迭代相邻小区,因为 UE 未连接到它们,所以相邻小区具有 null cid。

Here is a fix:这是一个修复:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM