getAllCellInfo() returns empty list in honor 9n

佐手、 提交于 2019-12-11 14:03:58

问题


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

    }

回答1:


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

getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()



回答2:


use

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

and use this instead of getCellLocation().

getNeighboringCellInfo()


来源:https://stackoverflow.com/questions/56376732/getallcellinfo-returns-empty-list-in-honor-9n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!