Search code examples
androidandroid-permissions

Android M - Is there any way to know whether a user has chosen to never see the grant permissions dialog ever again?


If an app calls ActivityCompat.requestPermissions(...), the OS displays a dialog with "Deny" and "Permit" buttons. There is also a "Never show this again" tick box.

There's no way that I can see for the app to know whether the user has ticked this box. Within onRequestPermissionsResult(...), the grantResults parameter is PERMISSION_DENIED if the user clicks "Deny" and also if the user ticks the tick box before clicking "Deny".

Is there any way an app can find out whether the user doesn't want to see that dialog again?


Solution

  • You can use shouldShowRequestPermissionRationale() - it will return false in a few cases:

    • You've never asked for the permission before
    • The user has checked the 'never again' checkbox
    • The permission has been disabled by policy (say, in a work situation)

    By combining this with a shared preference to store if you've ever asked for permission, you can effectively determine if they'll actually see the dialog when you call requestPermissions().