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