getAllCellInfo() returns 空列表以纪念 9n
getAllCellInfo() returns empty list in honor 9n
getAllCellInfo()
returns honor 9n
中的空列表。我用于获取 Cell id 和 Location 区号。那么我将如何获取小区 ID 和位置区号。
我也试过getCellLocation()
。当 GPS
打开时,我得到了 Cell id 和 Location area code。我想在 GPS
处于关闭状态时获取小区 ID 和位置区号。(OS Android 奥利奥)。
TelephonyManager tel = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
CellLocation gsmCellLocation1 = tel.getCellLocation();
if(gsmCellLocation1!=null){
Log.e("gsmCellLocation1: ", String.valueOf(gsmCellLocation1));
}else{
Log.e("gsmCellLocation1: ", "nul 1");
}
GsmCellLocation location33 = (GsmCellLocation) tel.getCellLocation();
if(location33!=null){
Log.e("location33: ", String.valueOf(location33));
}else{
Log.e("location33: ", "nul 33");
}
final List<CellInfo> gsmCellLocation2 = tel.getAllCellInfo();
if(gsmCellLocation2!=null){
Log.e("gsmCellLocation2: ", String.valueOf(gsmCellLocation2));
}else{
Log.e("gsmCellLocation2: ", "nul 2");
}
使用
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
并使用它代替 getCellLocation().
getNeighboringCellInfo()
如果用户在设备上禁用了设备位置 运行 Android 9,以下方法不提供结果:
getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()
我遇到了同样的问题,我的代码在 Android 版本低于 9 的设备上工作。当禁用设备位置时,getAllCellInfo() returns Android 9 我正在测试的设备。当设备位置开启时,一切正常。
getAllCellInfo()
returns honor 9n
中的空列表。我用于获取 Cell id 和 Location 区号。那么我将如何获取小区 ID 和位置区号。
我也试过getCellLocation()
。当 GPS
打开时,我得到了 Cell id 和 Location area code。我想在 GPS
处于关闭状态时获取小区 ID 和位置区号。(OS Android 奥利奥)。
TelephonyManager tel = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
CellLocation gsmCellLocation1 = tel.getCellLocation();
if(gsmCellLocation1!=null){
Log.e("gsmCellLocation1: ", String.valueOf(gsmCellLocation1));
}else{
Log.e("gsmCellLocation1: ", "nul 1");
}
GsmCellLocation location33 = (GsmCellLocation) tel.getCellLocation();
if(location33!=null){
Log.e("location33: ", String.valueOf(location33));
}else{
Log.e("location33: ", "nul 33");
}
final List<CellInfo> gsmCellLocation2 = tel.getAllCellInfo();
if(gsmCellLocation2!=null){
Log.e("gsmCellLocation2: ", String.valueOf(gsmCellLocation2));
}else{
Log.e("gsmCellLocation2: ", "nul 2");
}
使用
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
并使用它代替 getCellLocation().
getNeighboringCellInfo()
如果用户在设备上禁用了设备位置 运行 Android 9,以下方法不提供结果:
getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()
我遇到了同样的问题,我的代码在 Android 版本低于 9 的设备上工作。当禁用设备位置时,getAllCellInfo() returns Android 9 我正在测试的设备。当设备位置开启时,一切正常。