2

I added location permissions to my app. When installing the app now it asks the user for permission. This is my code:

if (fragment.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION) {
    fragment.requestPermissions(....);
}

But when I have my previous app verison installed, where I didn't have this location permission and update the app then it does not ask for permission, as

fragment.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION

returns false

Normally this should only return false when the user clicked "never ask again". What am I missing here?

progNewbie
  • 4,362
  • 9
  • 48
  • 107

1 Answers1

5

shouldShowRequestPermissionRationale() also returns false if the user has never been asked for permission before. That's why ideally you first ask for permission, you then check what the permission result object is through onRequestPermissionsResult, and follow any consequent request with the check for shouldShowRequestPermissionRationale() to see whether the user has checked the never ask again option.

EDIT- Check the example in this answer: https://stackoverflow.com/a/34612503/10300673

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
  • 1
    Thanks! Problem is, that I want to show a dialog before asking for the permission but I can't distinguish if its first time app opening or has already been pressed "never ask again". So I would need to store this info by myself. Correct? – progNewbie Mar 08 '19 at 16:51
  • @progNewbie You could allow the standard dialog the first time, and show your rationale only after the user has already denied it once. Otherwise, you'd need to use and save flags to separate the scenarios as you say. – Nikos Hidalgo Mar 08 '19 at 16:55