Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shouldShowRequestPermissionRationale return false the first time

The shouldShowRequestPermissionRationale method returns false the first time.

I have the following code in a Fragment:

if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
    requestPermissions(new String[]{READ_CONTACTS}, 0);
} else {
    Toast.makeText(getActivity(), "FALSE", Toast.LENGTH_SHORT).show();
    snackBarInfo.dismiss();
}

Has anyone else encountered this?

like image 884
Terry Grosso Avatar asked Aug 24 '17 20:08

Terry Grosso


1 Answers

Yes, this is by design. The idea is that if the permission is not granted and the shouldShowRequestPermissionRationale method returns false, then the app should request the permission from the OS.

When the user denies the permission request, then the shouldShowRequestPermissionRationale method will return true. At this point, you should show some custom UI to the user explaining why the permission is required.

See the Workflow for requesting permissions section in the Request app permissions page for further details.

like image 60
Adil Hussain Avatar answered Nov 05 '22 03:11

Adil Hussain