Skip to content

Instantly share code, notes, and snippets.

@Suchiq
Created Jun 22, 2021
Embed
What would you like to do?
For checking runtime permission
val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
when {
permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> {
// Precise location access granted.
}
permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> {
// Only approximate location access granted.
}
else -> {
// No location access granted.
}
}
}
//
// Before you perform the actual permission request, check whether your app
// already has the permissions, and whether your app needs to show a permission
// rationale dialog. For more details, see Request permissions.
locationPermissionRequest.launch(arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment