Deny doesn't work
ductranit opened this issue · 6 comments
ductranit commented
Here is my try:
askPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) { _ ->
Timber.d("accept permission WRITE_EXTERNAL_STORAGE")
}.onDeclined { e ->
if (e.hasDenied()) {
Toast.makeText(context, R.string.msg_permission_file, Toast.LENGTH_LONG).show()
e.askAgain()
return@onDeclined
}
if (e.hasForeverDenied()) {
Toast.makeText(context, R.string.msg_permission_file, Toast.LENGTH_LONG).show()
e.goToSettings()
}
}
There are 2 issues:
- When user deny permission, it can go to onDeclined callback, but the
askAgain()
doesn't work at all. In the RuntimePermission source code, thePermissionFragment oldFragment
is not null, but it doesn't visible. - When user select deny with
do not ask again
, theonDeclined
callback isn't callable forever. There is no way to handle permission after that.
I though deny is basic feature, mean it should be tested carefully?
florent37 commented
ok I'll try your code
florent37 commented
I think I found something
florent37 commented
I changed
class KotlinRuntimePermission(var runtimePermission: RuntimePermission) {
init {
runtimePermission.ask()
}
fun onDeclined(block: ((PermissionResult) -> Unit)) : KotlinRuntimePermission {
runtimePermission.onDenied(block)
return this
}
}
runtimePermission.onDenied(block)
by
runtimePermission.onResponse{
if(it.hasDenied() || it.hasForeverDenied()){
block(it)
}
}
florent37 commented
and all works fine
thanks for your issue :)
I send an update of this library
florent37 commented
you can try the TestActivity.kt
in this project, it contains your code !
florent37 commented
check the 1.0.5