I am a little bit curious about the new permission model for android M and above especially about the method "shouldShowRequestPermissionRationale()". In the Documentation :
To help find situations where the user might need an explanation, Android provides a utiltity method, shouldShowRequestPermissionRationale(). This method returns true if the app has requested this permission previously and the user denied the request.
Note: If the user turned down the permission request in the past and chose the Don't ask again option in the permission request system dialog, this method returns false. The method also returns false if a device policy prohibits the app from having that permission.
Ok , user rejected permission definitely. Now in code snipet from the same page:
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
The confusion come from the else bloc, it returned false then user rejected that permission, this means we keep asking the user for the prrmission he rejected and this is contradictory with best practices
My question is ; how can we implement a good logique for dealing with all this ?
shouldShowRequestPermissionRationale()
returnsfalse
, then you know that the user has permanently rejected the permission. In that case, you can do something in your UI to reflect the fact that you cannot proceed further, plus perhaps give the user the option to visit Settings to manually grant the permission. – EighthshouldShowRequestPermissionRationale
is currently broken in SDK 25.0.1. It will return false, even though it should return true. – SawtellerequestPermissions()
call will grant you the permission. As I noted in the comment, the user can grant the permission through Settings. – Eighth