android:无法获取lte cellid

bf1o4zei  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(642)

我正在尝试在我的应用程序中获取lte小区id号:

  1. TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  2. List<CellInfo> cellInfoList = tm.getAllCellInfo();
  3. for (CellInfo cellInfo : cellInfoList)
  4. {
  5. if (cellInfo instanceof CellInfoLte) {
  6. CellIdentityLte cellIdentityLte = ((CellInfoLte) cellInfo).getCellIdentity();
  7. cellID = cellIdentityLte.getCi();
  8. }
  9. }

但是 cellID = cellIdentityLte.getCi(); 总是返回2147483647,最大值表示有问题。
我想访问位置和读取电话状态的权限就足够了。play store上的其他应用程序正在为我提供正确的手机ID,因此该设备不是问题所在(并在多部手机上进行了测试)。顺便说一下,正在运行sdkv.30。

fzsnzjdm

fzsnzjdm1#

在for循环中获取值时,也会迭代相邻单元,因为ue没有连接到它们,所以它们的cid为空。
下面是一个解决方案:

  1. if (cellIdentityLte.getCi() != 0 && cellIdentityLte.getCi() != 2147483647)
  2. {
  3. cellID = cellIdentityLte.getCi();
  4. }

相关问题