Last active
October 9, 2021 14:55
-
-
Save ReactorboY/014297f6f4fc844dfbfe2ae23f166c29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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