Created
November 29, 2021 15:27
-
-
Save FStranieri/44af176aa6b2eceba82e00ac409bb73e to your computer and use it in GitHub Desktop.
Managing permissions with Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalPermissionsApi | |
@Composable | |
private fun BuildCameraUI() { | |
val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA) | |
PermissionRequired( | |
permissionState = cameraPermissionState, | |
permissionNotGrantedContent = { | |
Column( | |
Modifier | |
.fillMaxSize() | |
.then(Modifier.padding(16.dp)), | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
Text(stringResource(R.string.camera_permission_info_0)) | |
Spacer(modifier = Modifier.height(8.dp)) | |
Row { | |
Button(onClick = { | |
cameraPermissionState.launchPermissionRequest() | |
}) { | |
Text(stringResource(R.string.camera_permission_grantbutton_0)) | |
} | |
} | |
} | |
}, | |
permissionNotAvailableContent = { | |
Column( | |
Modifier | |
.fillMaxSize() | |
.then(Modifier.padding(16.dp)), | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
Text(stringResource(R.string.camera_permission_info_1)) | |
Spacer(modifier = Modifier.height(8.dp)) | |
Row { | |
Button(onClick = { | |
openSettingsScreen() | |
}) { | |
Text(stringResource(R.string.camera_permission_grantbutton_1)) | |
} | |
} | |
} | |
} | |
) { | |
---------------------- | |
YOUR MAIN LAYOUT | |
---------------------- | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment