Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop occurs when displaying SettingsDialog with onPermissionsDenied #11

Closed
Nunocky opened this issue Dec 4, 2021 · 1 comment

Comments

@Nunocky
Copy link

Nunocky commented Dec 4, 2021

Basic Information

Device type: Emulator (Pixel4 API 29)
OS version: Android 10
EasyPermissions version: 1.0.0

Question

Sorry for the series of questions.

I'm trying to create a function like "Open app settings when some permissions are permanently denied", but it doesn't work.

In the onPermissionsDenied callback, I evaluate somePermissionPermanentlyDenied() and open the SettingsDialog from there, but the Fragment from which the call is made is being called infinitely.

画面収録 2021-12-04 午前11 34 26

Is it wrong to try to open the SettingsDialog at this location? If so, how do I open the SettingsDialog correctly?

Code and logs

I have uploaded the source code to github.
https://github.com/Nunocky/EasyPermissionsStudy

    override fun onResume() {
        super.onResume()

        checkPermissions()
    }

    //  -----------------------------------------------
    //  permissions issue
    //  -----------------------------------------------
    private val requiredPermissions = listOf(
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.CAMERA,
    )

    private fun checkPermissions() {
        if (!EasyPermissions.hasPermissions(
                requireContext(),
                *(requiredPermissions.toTypedArray())
            )
        ) {
            // Do not have permissions, request them now
            EasyPermissions.requestPermissions(
                host = this,
                rationale = "permissions required",
                requestCode = REQUEST_PERMISSIONS,
                perms = requiredPermissions.toTypedArray()
            )
        }
    }

    override fun onPermissionsDenied(requestCode: Int, perms: List<String>) {
        if (EasyPermissions.somePermissionPermanentlyDenied(this, requiredPermissions)) {
            toast("somePermissionPermanentlyDenied")

            SettingsDialog.Builder(requireContext())
                .build()
                .show()
       }
    }
    
@jjerome00
Copy link

you need to remove your permission check from onResume()

@Nunocky Nunocky closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants