Skip to content

Instantly share code, notes, and snippets.

@traendy
Created March 29, 2019 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traendy/59f430a460f7029e2c2e104f0f43884f to your computer and use it in GitHub Desktop.
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.
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