Cannot resolve method checkSelfPermission

后端 未结 7 1069
南方客
南方客 2021-02-19 14:58

I\'m trying to make my app ready for Android 6 and now I\'m stuck to the point where you need to request and check permissions.

I tried the following from the docs:

7条回答
  •  既然无缘
    2021-02-19 15:59

    As silly as it maybe, it could be in the wrong place. I had the same problem. The bolded part is where I had originally put the code. The italic part is where it should have gone

    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            Log.i("-----------", location.toString());
        }
        **if (ContextCompat.checkSelfPermission(this, 
            Manifest.permission.ACCESS_FINE_LOCATION) != 
                PackageManager.PERMISSION_GRANTED) {'some code'}**
        }; 'End of LocationListener method
        *if (ContextCompat.checkSelfPermission(this, 
            Manifest.permission.ACCESS_FINE_LOCATION) != 
            PackageManager.PERMISSION_GRANTED) { 'some code'}*
    

提交回复
热议问题