Reputation: 181
I made an Android program for take document images with MediaStore.ACTION_IMAGE_CAPTURE but I don't want make a copy to the gallery. I tested on Android 9/12/13/14. On 9/13/14 doesn't make a copy immediately. But on 12 I can't get this to work. Please help me.
@Throws(IOException::class)
private fun createImageFile(): File {
val timeStamp: String =
SimpleDateFormat(
"yyyyMMdd_HHmmss",
Locale.getDefault()
).format(Date())
val imageFileName = "IMG_" + timeStamp + "_"
val storageDir =
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
val image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
)
stored.imageFilePath = image.absolutePath
return image
}
private fun takeAPicture() {
var photoFile: File? = null
try {
photoFile = createImageFile();
} catch (ex: IOException) {
// Error occurred while creating the File
}
if (photoFile != null) {
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
val author = "${packageName}.provider"
try {
val photoURI: Uri = FileProvider.getUriForFile(this, author, photoFile);
cameraIntent.putExtra(
MediaStore.EXTRA_OUTPUT,
photoURI
)
cameraIntent.putExtra("saveToGallery", false)
activityTakePictreLauncher.launch(cameraIntent)
} catch (ex: Exception) {
Log.e("MainActivity", ex.message.toString())
}
}
}
The files_path.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images"
path="Android/data/hu.infokristaly.docustorepictureapp/files/Pictures" />
</paths>
I neked solution similar to cameraIntent.putExtra("saveToGallery", false)
Upvotes: 0
Views: 53