我刚拿到LG G4手机,开启了开发者选项模式,尝试从Android Studio运行应用程序,但它无法识别我的手机.我甚至尝试从MTP切换到PTP,但仍然无法识别.我在那里尝试了很多资源,但仍然没有.请任何人可以帮忙吗?
我的Android版本是4.2.1,我正在尝试使用TelephonyManager.getAllCellInfo()方法.在我的清单文件我有ACCESS_COARSE_UPDATES,ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION权限.但是该方法返回null.
我读到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) …Run Code Online (Sandbox Code Playgroud)