googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.86k stars 1.46k forks source link

permission dialog not shown #285

Closed paradise0love closed 5 years ago

paradise0love commented 5 years ago

Basic Information

Device type: _xiaomi_4__ OS version: 6.01 EasyPermissions version: 3.0.0

not show permission dialog when press negative button of the rationaleDialog.

Here is the examples in the sample app,i just call locationAndContactsTask() wen called onPermissionsDenied.

   @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size());

        // (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
        // This will display a dialog directing them to enable the permission in app settings.
        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
            new AppSettingsDialog.Builder(this).build().show();
        } else {
            Log.d(TAG, "onPermissionsDenied:");
            locationAndContactsTask();
        }
    }
samtstern commented 5 years ago

@paradise0love how exactly does this fail? Do you see the log line Log.d(TAG, "onPermissionsDenied:");?

paradise0love commented 5 years ago

@samtstern yes ,It's the same on the emulator.
The problem is related to the following code; if (fragment instanceof RationaleDialogFragmentCompat) { Log.d(TAG, "Found existing fragment, not showing rationale."); return; }

2019-07-16 09:28:02.152 10961-10980/pub.devrel.easypermissions.sample D/EGL_emulation: eglMakeCurrent: 0x9f6ad4e0: ver 3 0 (tinfo 0xa904b730) 2019-07-16 09:28:02.321 10961-10980/pub.devrel.easypermissions.sample D/EGL_emulation: eglMakeCurrent: 0x9f6ad4e0: ver 3 0 (tinfo 0xa904b730) 2019-07-16 09:28:02.333 10961-10980/pub.devrel.easypermissions.sample I/chatty: uid=10082(pub.devrel.easypermissions.sample) RenderThread identical 2 lines 2019-07-16 09:28:02.337 10961-10980/pub.devrel.easypermissions.sample D/EGL_emulation: eglMakeCurrent: 0x9f6ad4e0: ver 3 0 (tinfo 0xa904b730) 2019-07-16 09:28:03.564 10961-10980/pub.devrel.easypermissions.sample D/EGL_emulation: eglMakeCurrent: 0x9f6ad4e0: ver 3 0 (tinfo 0xa904b730) 2019-07-16 09:28:03.567 10961-10961/pub.devrel.easypermissions.sample D/MainActivity: onRationaleDenied:124 2019-07-16 09:28:03.567 10961-10961/pub.devrel.easypermissions.sample D/MainActivity: onPermissionsDenied:124:2 2019-07-16 09:28:03.569 10961-10961/pub.devrel.easypermissions.sample D/MainActivity: onPermissionsDenied: 2019-07-16 09:28:03.571 10961-10961/pub.devrel.easypermissions.sample D/BSPermissionsHelper: Found existing fragment, not showing rationale. 2019-07-16 09:28:03.574 10961-10980/pub.devrel.easypermissions.sample D/EGL_emulation: eglMakeCurrent: 0x9f6ad4e0: ver 3 0 (tinfo 0xa904b730)

@Override
    public void showRequestPermissionRationale(@NonNull String rationale,
                                               @NonNull String positiveButton,
                                               @NonNull String negativeButton,
                                               @StyleRes int theme,
                                               int requestCode,
                                               @NonNull String... perms) {

        FragmentManager fm = getSupportFragmentManager();

        // Check if fragment is already showing
        Fragment fragment = fm.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
        if (fragment instanceof RationaleDialogFragmentCompat) {
            Log.d(TAG, "Found existing fragment, not showing rationale.");
            return;
        }

        RationaleDialogFragmentCompat
                .newInstance(rationale, positiveButton, negativeButton, theme, requestCode, perms)
                .showAllowingStateLoss(fm, RationaleDialogFragmentCompat.TAG);
    }
dong2hi commented 5 years ago

The same is true for oppo R15x

vmadalin commented 5 years ago

@Zdzzzzzzzzzzzz @paradise0love Thank you for the info, apparently this issue isn't related with the device, and is easy to reproduce by calling EasyPermissions.requestPermissions on the callback onPermissionsDenied:

@Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size());

        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
            new AppSettingsDialog.Builder(this).build().show();
        } else {
             // REQUEST HERE PERMISSIONS
        }
    }

Basically the RationaleDialogFragmentCompat isn't removed before callbacks has invoked making imposible to make another requestPermissions and display another rationale dialog again. The restriction was added for avoid to display multiple times the same dialog. For example if you remove manually the restriction the behaviour is the correct but if we cancel the second dialog this is display again due the invocation onPermissionsDenied

Demo: gif_demo_error gif_demo_ok

samtstern commented 5 years ago

I think this is actually the correct behavior. When a user denies you some permission you should not immediately ask for it again! You should either:

a) Explain why you need it. b) Tell them they operation they wanted to complete failed and wait for them to launch the flow again,