Created
March 29, 2019 17:47
-
-
Save traendy/59f430a460f7029e2c2e104f0f43884f to your computer and use it in GitHub Desktop.
Android Method to create an intent with ACTION_IMAGE_CAPTURE and file path.
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 takeAPicture() { | |
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent -> | |
takePictureIntent.resolveActivity(packageManager)?.also { | |
val photoFile: File? = try { | |
createImageFile(FILENAME) | |
} catch (ex: IOException) { | |
Log.e(TAG, ex.message) | |
null | |
} | |
photoFile?.also { | |
val photoUri: Uri = | |
FileProvider.getUriForFile(this, FILE_PROVIDER_AUTHORITY, it) | |
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri) | |
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment