Search code examples
androidandroid-permissions

Android M permission issue with Dialog "Don't ask again"


It's a easier way to grant permission by Scoped Directory Access,but Dialog will show a checkbox named "Don't ask again". If the user selects Don't ask again and denies the request, all future requests for the given directory from your app will be automatically denied, and no request UI will be presented to the user. if user regret or hit that checkbox by mistake,how can app remedy? app can't get permission dialog.

How can we handle this?


Solution

  • We should use shouldShowRequestPermissionRationale.Please go through this:

    private void insertDummyContactWrapper() {
            int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_CONTACTS);
            if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
                    if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)) {
                        showMessageOKCancel("You need to allow access to Contacts",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        requestPermissions(new String[] {Manifest.permission.WRITE_CONTACTS},
                                                REQUEST_CODE_ASK_PERMISSIONS);
                                    }
                                });
                        return;
                    }
                requestPermissions(new String[] {Manifest.permission.WRITE_CONTACTS},
                        REQUEST_CODE_ASK_PERMISSIONS);
                return;
            }
            insertDummyContact();
        }