Search code examples
androidcameragalleryandroid-gallery

How do I prevent a duplicate picture from adding to the gallery?


I use the following code to take a picture:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path + "/" + fileName)));
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

Now when I use this, it does save the picture where I specify above, but it also saves a second copy to the default image folder and adds it to the gallery.

I would simply delete the second file, but it seems it would be a tad dangerous as onActivityResult's intent parameter is always null after taking said picture, so I would have to attempt deleting the most recently saved picture.

Is there any way I can prevent this behavior or correct it by getting the URI of the dupicate picture?


Solution

  • Well I've determined that it is pretty much not possible. I am now using a SurfaceView with my own camera activity.