getAllCellInfo()以荣誉9n返回空列表 [英] getAllCellInfo() returns empty list in honor 9n
问题描述
getAllCellInfo()
返回honor 9n
中的空列表.我习惯于获取小区ID和位置区号.因此,我该怎么做才能获取单元格ID和位置区号.
getAllCellInfo()
returns empty list in honor 9n
. I am used for to get Cell id and Location area code. So what will i do to get Cell id and Location area code.
我也尝试过getCellLocation()
.打开GPS
时,我得到了单元格ID和位置区号. GPS
处于关闭状态时,我想获取单元格ID和位置区号.(OS Android Oreo).
I also tried getCellLocation()
. And I got Cell id and Location area code when GPS
is on. I want to get Cell id and Location area code when the GPS
is in off state.(OS Android Oreo).
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");
}
推荐答案
如果用户已禁用运行Android 9的设备上的设备位置,则以下方法不会提供结果:
If the user has disabled device location on a device running Android 9, the following methods don't provide results:
getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()
这篇关于getAllCellInfo()以荣誉9n返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!