[SOLVED] I want to grant a permission by using ```...
# compose
l
[SOLVED] I want to grant a permission by using
Copy code
val requestPermissionLauncher = rememberLauncherForActivityResult(
        ActivityResultContracts.RequestPermission()
    ) { isGranted ->
        ...
    }
and
requestPermissionLauncher.launch(permission)
. I have discovered that
requestPermissionLauncher.launch(permission)
is responsible for opening the "android permission prompt" but triggers the above callback in the first run with
false
without waiting for a user action. When I click "Allow" btn the callback is triggered with
true
. Is the first run with false inteded? Do we have to suspend here and wait for a user action somehow? I would expect that the callback is only triggered when a button of the prompt is clciked.
f
Where do you call the code? Inside
LaunchedEffect
?
l
No it's launched in
onClick
callback, so it's not affected by recomposition.
f
It does not happen for me, it's definitely not intended
l
My bad, I had another side effect which I could identify. It works like intended. Tahnks for your input
i
You might also look at Accompanist Permissions: https://google.github.io/accompanist/permissions/
l
Thanks Ian, but I favor to implement it myself for the learning effect