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
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 { | |
createImageFile() | |
} catch (ex: IOException) { | |
// Something went wrong | |
null | |
} | |
// 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