Skip to content

Instantly share code, notes, and snippets.

@ReactorboY
Last active October 9, 2021 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReactorboY/014297f6f4fc844dfbfe2ae23f166c29 to your computer and use it in GitHub Desktop.
Save ReactorboY/014297f6f4fc844dfbfe2ae23f166c29 to your computer and use it in GitHub Desktop.
@Composable
fun CheckForPermission() {
val result = remember {
mutableStateOf(false)
}
val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.RequestPermission()){
result.value = it
}
if (result.value) {
// Add your code here
} else {
Box(modifier = Modifier.fillMaxSize()) {
Button(onClick = { launcher.launch(Manifest.permission.ACCESS_COARSE_LOCATION) }, modifier = Modifier
.align(Alignment.Center)) {
Text(text = "Check Permission", modifier = Modifier.align(Alignment.CenterVertically))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment