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

Kotlin implementation - both blocks called #10

Closed
elroid opened this issue Jun 12, 2018 · 2 comments
Closed

Kotlin implementation - both blocks called #10

elroid opened this issue Jun 12, 2018 · 2 comments

Comments

@elroid
Copy link

elroid commented Jun 12, 2018

I used the Kotlin code sample as a basis and came up with the following:

askPermission(Manifest.permission.CALL_PHONE) { res ->
	i { "all of your permissions have been accepted by the user: ${res.accepted}" }
	i { "... and denied: ${res.denied}" }
	val i = Intent(Intent.ACTION_CALL)
	i.data = Uri.parse("tel:01234 56789")
	startActivity(i)
}.onDeclined { e ->
	i { "Permissions declined: ${e.denied}" }
	i { "...and accepted: ${e.accepted}" }
}

I then called the function and chose to deny the permission. What I expected to happen was the bottom block to be called and the top to be untouched, what I actually saw is that both blocks get called - first the second, then the first. Here's the output:

I/Permissions declined: [android.permission.CALL_PHONE]
I/...and accepted: []
I/all of your permissions have been accepted by the user: []
I/... and denied: [android.permission.CALL_PHONE]

I solved the issue by modifying it somewhat:

askPermission(Manifest.permission.CALL_PHONE) { res ->
	res.accepted.filter { it == CALL_PHONE }.forEach {
		i { "the ${res.accepted} permission has been accepted by the user" }
		val i = Intent(Intent.ACTION_CALL)
		i.data = Uri.parse("tel:01234 56789")
		@Suppress("ConvertToStringTemplate")
		startActivity(i)
	}
}.onDeclined { e ->
	i { "Permissions declined: ${e.denied}" }
}

Which works, but is not quite as elegant as the docs suggest it should be.

Also note the call to @Suppress("ConvertToStringTemplate") - this is to suppress the usual permissions lint error that we should try/catch a security exception. If there is any way this library can suppress that warning that would be ideal.

@florent37
Copy link
Owner

my falt, the first is not triggered by onAccepted, but by onResult, i change that

@vishnuharidas
Copy link

Is this issue fixed? I tried in version 1.0.1 and still it calls both the blocks even if I deny.

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

3 participants