Prevent image capture using an Android camera in the gallery

I am trying to save an image captured using an Android camera in a normal place. My code is as follows:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File f = File(android.os.Environment.getExternalStorageDirectory(), "test.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, SUB_ACTIVITY_CAMERA_PREVIEW);

The image is saved in the right place, but it is also saved in the default camera folder, which causes it to be displayed in the gallery. Any suggestions?

+3
source share
1 answer

Include an empty file with the name .nomediain the external file directory (note the dot prefix in the file name). This will prevent you from reading Android media files and including them in applications such as Gallery or Music.

+1
source

All Articles