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

onRationaleAccepted and onRationaleDenied implemented in Fragment are not called #10

Open
Nunocky opened this issue Dec 4, 2021 · 2 comments

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

When I was implementing the EasyPermissions feature in Fragment, I noticed that these callback functions were not being called, even though I implements EasyPermissions.RationaleCallbacks.

画面収録 2021-12-04 午前11 28 29

I investigated in the debugger and found the following

Execute EasyPermissions.requestPermissions, passing MainFragment as the host.

FFu8nI6aUAAzDh2

PermissionRequest.Builder(host.context) is called. host.context = MainActivity

FFu9GfmaIAAzeem

MainActivity does not implement EasyPermissions.RationaleCallbacks, so onRationaleAccepted and onRationaleDenied will not be called.

FFu8bGqacAMfqKR

Is this the correct behavior? Should EasyPermissions.RationaleCallbacks be implemented only in Activity?

Code

The source code has been uploaded to github.
https://github.com/Nunocky/EasyPermissionsStudy

class MainFragment : Fragment(), EasyPermissions.PermissionCallbacks,
    EasyPermissions.RationaleCallbacks {

    private val requiredPermissions = listOf(
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.CAMERA,
    )
...

    override fun onResume() {
        super.onResume()
        checkPermissions()
    }

    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()
            )
        }
    }

...
    // TODO : not called?
    override fun onRationaleAccepted(requestCode: Int) {
        toast("onRationaleAccepted")
    }

    // TODO : not called?
    override fun onRationaleDenied(requestCode: Int) {
        toast("onRationaleDenied")
    }
}
@ymmtyuhei
Copy link

Basic Information

Device type: Emulator (Pixel3a API 31)
OS version: Android 12
EasyPermissions master branch sample.

Question

I have try easypermissions-ktx's sample project.
When denied SMS(which request permissions from MainFragment.kt), and then allowed it again, MainFragment.kt :: onPermissionGranted was not called. (MainActivity.kt :: onPermissionGranted was called. )

When pass through the rationale dialog, onPermissionGranted in the fragment is not called ?
(Immediately allows the same permission from fragment, then onPermissionGranted in Fragment was called.)

easypermission-try.mov

@ymmtyuhei
Copy link

This casting context to Fragment doesn't seem to be succeeding.

is Fragment ->
PermissionsHelper
.newInstance(context)
.directRequestPermissions(model.code, model.perms)

image

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