Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launchPermissionRequest() in jetpack accompanist does nothing

In my app I have to ask for permission to write to external storage in order to save bitmap for ability to share it. Now looking at the code below, whenever I call it, alert dialog appears, but no permission request appears from Android itself. All I can see in the log is Let's launch permission request. How to appropriately show the permission window from Android to get that permission? Thank you.

@ExperimentalPermissionsApi
@Composable
fun Permission(
    permission: String = android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
    rationale: String = "This permission is important for this app. Please grant the permission.",
    permissionNotAvailableContent: @Composable () -> Unit = { },
    content: @Composable () -> Unit = { }
) {
    val permissionState = rememberPermissionState(permission)
    PermissionRequired(
        permissionState = permissionState,
        permissionNotGrantedContent = {
            Rationale(
                text = rationale,
                onRequestPermission = {
                    println("Let's launch permission request.")
                    permissionState.launchPermissionRequest()
                }
            )
        },
        permissionNotAvailableContent = permissionNotAvailableContent,
        content = content
    )
}

@Composable
private fun Rationale(
    text: String,
    onRequestPermission: () -> Unit
) {
    AlertDialog(
        onDismissRequest = { /* Don't */ },
        title = {
            Text(text = "Permission request")
        },
        text = {
            Text(text)
        },
        confirmButton = {
            Button(onClick = onRequestPermission) {
                Text("Ok")
            }
        }
    )
}
like image 358
Captain Jacky Avatar asked Oct 24 '25 14:10

Captain Jacky


1 Answers

Just so that no one misses the possible solution as mentioned by ADM in the comments.

The Solution by ADM: Check if you have added the permission in the manifest

like image 189
AleksejB Avatar answered Oct 26 '25 05:10

AleksejB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!