Android:无法获得 LTE CellId

问题描述

我正在尝试在我的应用中获取 LTE 蜂窝 ID 号:

Sub processpershingManual()

Dim lst As Excel.ListObject
Dim lstRow As Excel.ListRow
Dim ListColumns As String
  
Dim rngHedgeServeTemplate As Excel.Range
Dim rngPershingTemplate As Excel.Range
Dim bHedgeServeRecord As PershingTemplate

Application.ScreenUpdating = False

Set bHedgeServeRecord = New PershingTemplate


If lst.ListColumns("Execbroker") = "ABCD" Then
 
If shtman.ListObjects.Count <> 0 Then
    For Each lst In shtman.ListObjects
        lst.Unlist
    Next lst
End If

End If

但是 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(); } } 总是返回 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();
}