permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.22k stars 1.44k forks source link

Do not call requestPermissions if permission was already denied permanently #590

Closed WonderCsabo closed 3 years ago

WonderCsabo commented 5 years ago

Overview

The library ask for permissions even if the user permanently denied it before (checked "Do not ask again"). This adds an unnecessary call, and also notifies the app about a user action which is not happening (the permission dialog is not shown actually).

Expected

If we detekt the user already denied the permission with never ask again, we should not call requestPermissions().

Actual

Currently we always call requestPermissions(), regardless the user denied it permanetly before or not.

Pseudo solution

fun WelcomeScreenFragment.welcomeButtonClickedWithPermissionCheck() {
    if (PermissionUtils.hasSelfPermissions(this.requireActivity(),
                    *PERMISSION_WELCOMEBUTTONCLICKED)) {
        welcomeButtonClicked()
    } else {
        if (PermissionUtils.shouldShowRequestPermissionRationale(this,
                        *PERMISSION_WELCOMEBUTTONCLICKED)) {
            this.requestPermissions(PERMISSION_WELCOMEBUTTONCLICKED, REQUEST_WELCOMEBUTTONCLICKED)
        }
    }
}
hotchemi commented 5 years ago

Thank you for your suggestion and that makes a lot of sense! Would you mind open a PR? 👀

WonderCsabo commented 5 years ago

I try to find the time to do it!

isabsent commented 5 years ago

Does this issue exist for Kotlin only or Java is suffered to it too?

WonderCsabo commented 5 years ago

I experienced it using Java. I think this issue is language independent.

kaushalyap commented 4 years ago

actually if permission is denied permanently, app should allow user to go to settings and rectify it, since it is good UX

hotchemi commented 3 years ago

let us close the issue as:

we're still welcome for PR.