Android getAllCellInfo()返回空列表以表示敬意9n
Android getAllCellInfo()返回空列表以表示敬意9n,android,android-8.0-oreo,Android,Android 8.0 Oreo,getAllCellInfo()在honor 9n中返回空列表。我用于获取手机id和位置区号。那么我该怎么做才能得到手机号和位置区号呢 TelephonyManager tel = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); if (A
getAllCellInfo()
在honor 9n
中返回空列表。我用于获取手机id和位置区号。那么我该怎么做才能得到手机号和位置区号呢
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");
}
我还尝试了getCellLocation()
。当GPS
开启时,我得到了手机id和位置区号。当GPS
处于关闭状态时,我想获取手机id和位置区号
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");
}
TelephonyManager tel=(TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE);
if(ActivityCompat.checkSelfPermission(getContext(),Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予&&
ActivityCompat.checkSelfPermission(getContext()、Manifest.permission.ACCESS\u\u位置)!=PackageManager.permission\u已授予){
考虑到呼叫
//ActivityCompat#请求权限
//在此处请求缺少的权限,然后覆盖
//public void onRequestPermissionsResult(int-requestCode,字符串[]权限,
//int[]格兰特结果)
//处理用户授予权限的情况。请参阅文档
//对于ActivityCompat,请请求权限以获取更多详细信息。
回来
}
CellLocation gsmCellLocation1=tel.getCellLocation();
如果(gsmCellLocation1!=null){
Log.e(“gsmCellLocation1:”,String.valueOf(gsmCellLocation1));
}否则{
Log.e(“gsmCellLocation1:,“num1”);
}
GsmCellLocation location33=(GsmCellLocation)电话:getCellLocation();
如果(位置33!=null){
Log.e(“location33:,String.valueOf(location33));
}否则{
Log.e(“位置33:,“编号33”);
}
最终列表gsmCellLocation2=tel.getAllCellInfo();
如果(gsmCellLocation2!=null){
Log.e(“gsmCellLocation2:”,String.valueOf(gsmCellLocation2));
}否则{
Log.e(“gsmCellLocation2:,“nul2”);
}
使用
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的设备上禁用了设备位置,则以下方法不会提供结果:
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");
}
getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()
我也有同样的问题,我的代码在Android版本低于9的设备上运行。当设备位置被禁用时,getAllCellInfo()在我正在测试的Android 9设备中返回一个空列表。当设备位置打开时,一切正常。我已经在使用该权限,并且已经尝试GetNeightringCellInfo(),它也会重新运行空列表
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");
}