Created
June 29, 2022 01:33
-
-
Save navczydev/0ceb885ac2cdab0b3e14eb6ff52b2fb7 to your computer and use it in GitHub Desktop.
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