RxPermissions icon indicating copy to clipboard operation
RxPermissions copied to clipboard

Immediate permission request won't work if there has been some pending requests after configuration change

Open zourb opened this issue 6 years ago • 2 comments

Reproduce procedure in sample project:

  1. Add some immediate permission request in onCreate method of the MainActivity
compositeDisposable.add(rxPermissions.requestEach(permission.READ_EXTERNAL_STORAGE, permission.WRITE_EXTERNAL_STORAGE, permission.SEND_SMS)
                .subscribe(new Consumer<Permission>() {
                    @Override
                    public void accept(Permission permission) throws Exception {
                    }
                }));
  1. Click the button for CAMERA permission request
  2. Rotate the phone after the permission dialog appearing
  3. Then subsequent READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE requests won't trigger the permission dialog

zourb avatar Dec 29 '18 09:12 zourb

The main point described above is: immediate permission request if there has been some pending requests after configuration change will result the empty permissions and results arrays which should be treated as a cancellation in the onRequestPermissionsResult callback.

/**
     * Callback for the result from requesting permissions. This method
     * is invoked for every call on {@link #requestPermissions(String[], int)}.
     * <p>
     * <strong>Note:</strong> It is possible that the permissions request interaction
     * with the user is interrupted. In this case you will receive empty permissions
     * and results arrays which should be treated as a cancellation.
     * </p>
     *
     * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
     * @param permissions The requested permissions. Never null.
     * @param grantResults The grant results for the corresponding permissions
     *     which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED}
     *     or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null.
     *
     * @see #requestPermissions(String[], int)
     */
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults) {
        /* callback - do nothing */
    }

thus, the permission entry of mSubjects in RxPermissionsFragment won't be removed.

zourb avatar Dec 29 '18 09:12 zourb

The working demo: https://github.com/zourb/RxPermissions

zourb avatar Dec 29 '18 10:12 zourb