Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2022 01:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
private fun launchCameraIntent() {
val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Ensure that there's a camera activity to handle the intent
// Android11 or higher needs the <query> tag to be added in the Android Manifest file.
// It depend on the device, if by-default camera package is visible or not
takePhotoIntent.resolveActivity(packageManager)?.also {
// Create the File where the photo should go
val photoFile: File? = try {
} catch (ex: IOException) {
// Something went wrong
// launch camera intent only if the File was successfully created
photoFile?.let {
val photoURI: Uri = // get photo file URI
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(takePhotoIntent, REQUEST_IMAGE_CAPTURE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment