13

I am using the Camera Activity to capture the picture. I call it with the MediaStore.EXTRA_OUTPUT extra parameter. The image is correctly saved to provided path, put it is saved also to the gallery folder, so I can view the image in "Gallery" application - can I avoid this?

...
File file = new File(Environment.getExternalStorageDirectory(), "Test.jpg" );
iImageOutputUri = Uri.fromFile( file );

// Start camera intent to capture image
Intent intent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, iImageOutputUri );
startActivityForResult( intent, CAPTURE_IMAGE );
...

Thanks

STeN
  • 6,262
  • 22
  • 80
  • 125
  • +1 for good question. I was always wondering why all my applications using the camera are saving the pictures in the gallery as well. – Chris Mar 07 '11 at 15:58
  • 3
    I came to a conclusion that you cannot really predict on what camera activity really does. It partially depends on how customized android version is (thus a custom camera activity, etc.). The only way to solve this is to write your own camera activity. For me it was the easiest way to work around all the quirks and not to use any hacks. – Audrius Mar 07 '11 at 17:11
  • 3
    Hi Audrius, I agree with you - it depends on the device - on some phones it is saving the image also to gallery (e.g. LG-P500), on some not (e.g. Samsung Nexus S). Many aspects of the camera activity are pretty bad, it does not allow to specify parameters, like the minimum/maximum image quality, which is totally up to user, it cannot return the JPEG in buffer, for e.g. further processing, etc. It is very simple to be used, but not as good as it can be. On the next project I will do my own camera handling... Bye – STeN Mar 08 '11 at 04:57
  • Is there a way to find out (reliabli) the url of the duplicate/undesired saved image? (i mean the one that is saved in the default camera folder which should not be saved at all)? Because if so, as a workaround one could delete that one... – matteo Dec 28 '11 at 15:28
  • 2
    @matteo Check this out: http://stackoverflow.com/questions/6390163/deleting-a-gallery-image-after-camera-intent-photo-taken not pretty but I tried it and it sort of works. I don't refer to the accepted answer though - I tried Emil's approach. – AgentKnopf Apr 13 '12 at 09:06

3 Answers3

2

Just replace your code

File file = new File(Environment.getExternalStorageDirectory(), "Test.jpg" );

with following code

File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "Test.jpg");

Description of getExternalFilesDir() : Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory()) where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media.

Avijit
  • 3,834
  • 4
  • 33
  • 45
Shailendra Patil
  • 377
  • 2
  • 19
0

How about saving your images with non-image extension ? Something like michael.photo instead of michael.jpg/png etc.That way Gallery app wont take them in and I have seen many such apps keepsafe for example does this.

user2886615
  • 81
  • 1
  • 2
-3

I don't believe you can avoid this. The gallery application looks through your SD card for images and displays them automatically.

Anzu
  • 1
  • 2
    This is not the point. The point is that the image is actually saved twice: once at the location provided as EXTRA_OUTPUT plus once at the default location. That's what the OP wants to avoid – matteo Dec 28 '11 at 15:23