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

Not work well with kotlin coroutine #719

Open
taolulu opened this issue Mar 15, 2021 · 4 comments
Open

Not work well with kotlin coroutine #719

taolulu opened this issue Mar 15, 2021 · 4 comments

Comments

@taolulu
Copy link

taolulu commented Mar 15, 2021

Overview

I'm using the ktx library. Since I want to handle each type of permission denied event separately, I was trying to convert the callback API to coroutine and call every kind of permission request sequentially. Then I found that after the first coroutine executed and the request dialog was showed, the next coroutine will be inactive, and could not to resume, thus the future coroutines could not be execute.
I also found that when all the permissions was granted, the coroutine sequence could execute correctly. The only difference between the two cases is whether or not a permission request dialog pops up.

Expected

Permission request coroutine could run correctly.

Actual

After a permission request dialog was showed, the next coroutine will be inactive.

Environment

permissionsdispatcher-ktx:1.0.1

@hotchemi
Copy link
Member

thx for the report, could we possibly get a minimum example project to repro the issue? 🙏

@taolulu
Copy link
Author

taolulu commented Mar 19, 2021

a simple demo:

fun FragmentActivity.pickPhoto() {
    GlobalScope.launch {
        catchAll {
            requestSinglePermission(this@pickPhoto, Manifest.permission.CAMERA)
            requestSinglePermission(
                    this@pickPhoto,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
            // do works after granted
        }
    }
}

// make callback as coroutine API
suspend fun requestSinglePermission(fragmentActivity: FragmentActivity, vararg permissions: String): Boolean {
    return suspendCancellableCoroutine {
        fragmentActivity.constructPermissionsRequest(
                *permissions,
                onShowRationale = { it.proceed() },
                onPermissionDenied = {
                    it.cancel()
                },
                onNeverAskAgain = {
                    it.cancel()
                }
        ) {
            if (it.isActive) {
                it.resume(true)
            }
        }.launch()
    }
}

I don't know if it's possible to make this work. But what I really need is a parameter who can let me know witch permission(s) has been denied.

@hotchemi
Copy link
Member

thx, let us check

@Toygun3421
Copy link

#730 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants