Skip to content

Instantly share code, notes, and snippets.

@john-lorrenz
Last active December 22, 2019 21:34
Show Gist options
  • Save john-lorrenz/b7bd37ff3240627a7e121262a19a03a5 to your computer and use it in GitHub Desktop.
Save john-lorrenz/b7bd37ff3240627a7e121262a19a03a5 to your computer and use it in GitHub Desktop.
Camera capture full quality
// uri exposure fix
var builder = StrictMode.VmPolicy.Builder()
StrictMode.setVmPolicy(builder.build())
// Class level variable
var photoURI: Uri? = null
// STEP 1: Call this where you need to do the capturing
fun openCamera(fileName: String, requestCode: Int){
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE);
var file = File(this.externalCacheDir, fileName)
photoURI = Uri.fromFile(file)
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(intent, requestCode)
}
// STEP 2: Take this as example
fun sampleUsage(){
openCamera("[Some File Name].jpg", [Some request code])
}
// STEP 3: Do what you need to do with the image URI
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// Sample of what to do with the uri - set as content of an image view
[Some image view].setImageURI(photoURI)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment