Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

"Don't show again" behavior #190

Closed adrcotfas closed 6 years ago

adrcotfas commented 6 years ago

Not actually an issue but a feature proposal:

This may be implemented with the persistence of the isPermanentlyDenied from showPermissionDenied and creating the snackbar according to this but do you have a simpler idea?

adrcotfas commented 6 years ago

Ok, I managed to figure it out: Just don't check for the permission if the user toggled "Don't show again" which is equivalent to !showSnackbar in this case. Thanks for the library!

    boolean showSnackbar = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        showSnackbar = shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)
                && checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED;
    }
    if (showSnackbar)
    {
        Dexter.withActivity(this)
                .withPermission(Manifest.permission.READ_CONTACTS)
                .withListener(contactsPermissionListener)
                .check();
    }