Created
August 20, 2023 01:03
-
-
Save jianastrero/9479c282204c4e3dc85eeca05a67ee5b to your computer and use it in GitHub Desktop.
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
@Composable | |
private fun MainContent() { | |
// Initialize Compose Permission | |
// This uses remember under the hood so there's no need to remember it | |
val cameraPermission = composePermission(permission = android.Manifest.permission.CAMERA) | |
Column( | |
horizontalAlignment = Alignment.CenterHorizontally, | |
verticalArrangement = Arrangement.Center, | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(24.dp) | |
) { | |
Text( | |
text = "Granted: ${cameraPermission.isGranted}", | |
color = if (cameraPermission.isGranted) Color.Green else Color.Red, | |
fontSize = 24.sp, | |
fontWeight = FontWeight.Black | |
) | |
Button( | |
onClick = { | |
if (cameraPermission.isGranted) { | |
/* Do Something */ | |
} else { | |
// Request the permission | |
cameraPermission.request() | |
} | |
}, | |
modifier = Modifier.padding(top = 12.dp) | |
) { | |
Text(text = "Request Permission") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment