1

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")
            }
        }
    )
}
Captain Jacky
  • 888
  • 1
  • 12
  • 26

1 Answers1

2

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

SpawnTheTronix
  • 152
  • 1
  • 7