OnRequestPermissionsResult returns immediately with denied permission

My Android app needs to request permission for location services. I am doing this with:

ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE_ACCESS_COARSE_LOCATION); 

But immediately after this is called, onRequestPermissionsResult returns immediately with the permission allowed:

 @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case REQUEST_CODE_ACCESS_COARSE_LOCATION: { } } } 

Permission is specified in the manifest:

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

I also cleared the cache to prevent any previous negation that the user gave in order to influence this.

I expect that a dialog box will appear asking you to grant the user permission or a ban on the provision of location services, but it does not appear.

+5
source share
2 answers

Edit:

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

in

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

Resolution for “coarse” location data (ie, not fine-grained), and not “course” location data (for example, where any university class is located).

+6
source
 private int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 100; private void checkPermission() { if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(newString[{Manfest.permission.ACCESS_COARSE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION); } else { doShowLocation(); } } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) { showContacts(); } } 
0
source

Source: https://habr.com/ru/post/1257875/


All Articles