问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/55066714/shouldshowrequestpermissionrationale-is-false