florent37/RuntimePermission

Deny doesn't work

ductranit opened this issue · 6 comments

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:

  1. When user deny permission, it can go to onDeclined callback, but the askAgain() doesn't work at all. In the RuntimePermission source code, the PermissionFragment oldFragment is not null, but it doesn't visible.
  2. When user select deny with do not ask again, the onDeclined 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?

ok I'll try your code

I think I found something

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

and all works fine

thanks for your issue :)

I send an update of this library

you can try the TestActivity.kt in this project, it contains your code !

check the 1.0.5