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

1 android telephonymanager cellinfo

我读到getAllCellInfo(所有帖子),并有像类似的情况。下面发布的代码在 Android 6 (OnePlus One) 上运行良好,但在 Google Nexus 5x Android 8.1 API 27 上返回一个空的 Cellinfo 列表。我在清单中设置了 Permission ACCESS CORSE LOCATION 并在第一次运行应用程序时请求许可.

这是一个代码片段:

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";
    }
}
Run Code Online (Sandbox Code Playgroud)

尝试使用“Network Cell Info lite”等其他应用程序时,这些应用程序会获取所有单元信息:(

非常感谢任何帮助。

Ana*_*and 5

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

如果您想访问,getAllCellInfo()您也需要启用定位服务