Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent image captured via android camera to show up in gallery

I'm trying to save the image captured via android camera in a custom location. My code looks like this:

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 being saved to the desired location but it is also being saved to the default camera folder which is causing it to be displayed in the gallery. Any suggestions?

like image 761
bala Avatar asked Jan 24 '26 18:01

bala


1 Answers

Include an empty file named .nomedia in your external files directory (note the dot prefix in the filename). This will prevent Android's media scanner from reading your media files and including them in apps like Gallery or Music.

like image 131
Labeeb Panampullan Avatar answered Jan 27 '26 08:01

Labeeb Panampullan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!