getAllCellInfo() returns empty list in honor 9n

2019-08-19 02:35发布

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.

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");

    }

2条回答
Evening l夕情丶
2楼-- · 2019-08-19 03:02

If the user has disabled device location on a device running Android 9, the following methods don't provide results:

getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()
查看更多
3楼-- · 2019-08-19 03:26

use

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

and use this instead of getCellLocation().

getNeighboringCellInfo()
查看更多
登录 后发表回答