我阅读了所有关于 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/