Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Created March 6, 2021 16:10
Show Gist options
  • Save Kashif-E/bd8f057861c465ffb805ea0fd6a9f343 to your computer and use it in GitHub Desktop.
Save Kashif-E/bd8f057861c465ffb805ea0fd6a9f343 to your computer and use it in GitHub Desktop.
private val cameraPermission =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
with(binding.root) {
when {
granted -> {
showToastMessageInCenter("Permission Granted")
startCamera()
}
shouldShowRequestPermissionRationale(Manifest.permission.CAMERA) -> {
//this will be shown if the phone is running on api level > 23 else only classic dialog will be shown
showToastMessageInCenter("Permission Denied,Permission is needed to take photos")
}
else -> showToastMessageInCenter("Permission Denied")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment