android - getAllCellInfo() 在 Nexus 5x 上返回空列表

标签 android telephonymanager cellinfo

我阅读了所有关于 getAllCellInfo() 的帖子并且遇到了类似 this 的情况. 下面发布的代码在 Android 6 (OnePlus One) 上运行良好,但在 Google Nexus 5x Android 8.1 API 27 上返回一个空的 Cellinfo 列表。 我已在 list 中设置权限 ACCESS CORSE LOCATION 并在首次运行应用程序时请求权限。

这是一个代码 fragment :

try {

        TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        String networkOperator = "";
        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) { 
            networkOperator = tm.getNetworkOperator(); 
        }

        if (!TextUtils.isEmpty(networkOperator)) { //is not empty with Nexus 5x
            mcc = networkOperator.substring(0, 3); 
            mnc = networkOperator.substring(3);
        } else {
            mcc = "Unbekannt";
            mnc = "Unbekannt";
        }

        List<CellInfo> cell = tm.getAllCellInfo();
        System.out.println("List: "+cell);
        if (cell != null) { //Always null with Nexus 5x
          //  TODO
        } else {
            cellID = "ERROR";
            lac = "ERROR";
        }
    }
    catch(Exception ex) {
        mcc = "No Permission";
        mnc = "No Permission";
        cellID = "ERROR";
        lac = "ERROR";
    }
}

当尝试其他应用程序如“Network Cell Info lite”时,这些应用程序会获取所有的小区信息:(

非常感谢任何帮助。

最佳答案

在 Android 8.0 及更高版本中,要访问 getAllCellInfo(),您的应用应位于前台。

如果你想访问getAllCellInfo(),你需要启用Location Service也是。

关于android - getAllCellInfo() 在 Nexus 5x 上返回空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092791/

相关文章:

android - 在 Android 中为定期工作管理器设置初始延迟

java - 获取双 SIM 卡安卓手机的 SimOperatorName

android - TelephonyManager 并未在每台设备上提供电话号码

android - 收集 5G 小区数据(New Radio)

android - 测量5G(新 radio )数据

java - 自定义数据方案上的 Android ActivityNotFoundException

java - 使用 Eclipse IDE 排除第 3 方库,它是来自 ProGuard 的类和子类

android - 套接字和 SDK 最低版本

android - 使用 BroadcastListener 通话结束后从 Calllog 中获取通话持续时间

android - getAllCellInfo() 在华为荣耀 7 中返回一个空列表