By using a camera intent to take a picture in my app, images was duplicated from SD card and Gallery. Here my code to take picture:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = "file to /storage/emulated/0/Pictures/folder/image.jpg"
} catch (IOException ex) {
// Error occurred while creating the File
Log.e("Can't create file", ex.getLocalizedMessage());
}
Uri photoUri = Uri.fromFile(photoFile);
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}
Image saved to photoFile
and another same saved to Gallery. How to resolved it?
I assume that you want the image saved in the SD card but not in the gallery? If so, try saving the photo in the app's private space in the external memory of the device rather than in the public Pictures directory. I did it in my app like this: