Search code examples
androidandroid-permissionsandroid-security

Android on demand permission request


How to handle don't ask me again in android on demand permission request. Is their any best practice if the user chooses don't ask me again and later if he want to get access any best practice suggestion? Thanks.


Solution

  • shouldShowRequestPermissionRationale will help you with this.

    shouldShowRequestPermissionRationale() will be used to check whether user have selected Never ask again. It will return value as True or False, If user have selected Never ask before it will return false, else will return true.

    boolean shouldShow = shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE);
    if (!shouldShow) {
        // show some dialog which will give information about required permission, so that user can understand what is need of that permission.
    }
    

    on button click of dialog, you can redirect user to setting screen of app.

    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,Uri.fromParts("package", getPackageName(), null));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    

    If you are working for pre-marshmallow, you need to use ActivityCompat.shouldShowRequestPermissionRationale()