getAllCellInfo()以荣誉9n返回空列表

时间:2019-05-30 10:46:09

标签: android android-8.0-oreo

getAllCellInfo()honor 9n中返回空列表。我习惯于获取小区ID和位置区号。所以我该怎么做才能获得小区ID和位置区号。

我也尝试过getCellLocation()GPS打开时,我得到了单元格ID和位置区号。我想在GPS处于关闭状态时获取单元格ID和位置区号。(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");

    }

3 个答案:

答案 0 :(得分:0)

使用

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

并使用它代替getCellLocation().

getNeighboringCellInfo()

答案 1 :(得分:0)

如果用户已禁用运行Android 9的设备上的设备位置,则以下方法不会提供结果:

"@angular/cli": "7.1.0"

答案 2 :(得分:0)

我遇到了同样的问题,我的代码在Android版本小于9的设备中运行。禁用设备位置后,getAllCellInfo()在我正在测试的Android 9设备中返回一个空列表。打开设备位置后,一切正常。