tbruyelle / RxPermissions

Android runtime permissions powered by RxJava2
Apache License 2.0
10.48k stars 1.31k forks source link

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

Open zourb opened 5 years ago

zourb commented 5 years ago

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 {
                    }
                }));
  2. Click the button for CAMERA permission request
  3. Rotate the phone after the permission dialog appearing
  4. Then subsequent READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE requests won't trigger the permission dialog
zourb commented 5 years ago

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 commented 5 years ago

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