Skip to content

Instantly share code, notes, and snippets.

@Suchiq
Created June 22, 2021 11:33
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 Suchiq/20ee4b5087ecdf7b2b2124b82f46dae7 to your computer and use it in GitHub Desktop.
Save Suchiq/20ee4b5087ecdf7b2b2124b82f46dae7 to your computer and use it in GitHub Desktop.
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