Avoid that the gallery saves the picture taken with the camera in Android


December 2018


1.9k time


I have an application that allows the user to take a picture with the native camera of the phone, I don't want to implement all the functionality of a camera (I don't want to loose the autofocus, flash or some other properties that the native camera might have) so I make this call:

File folder = new File(Environment.getExternalStorageDirectory(),"folder");
    File nomedia = new File(folder,".nomedia");
    }catch (IOException e){
        Log.e("error", e.getMessage());

    File file = new File(folder,"image.jpeg");
    try {
    } catch (IOException e) {
    imageUri = Uri.fromFile(file);
    if(imageUri != null){   
        Log.i(TAG, "imageUri: " + imageUri.getPath());
        imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

Then in a button I have the execution of the intent:

startActivityForResult(imageIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

This works perfectly, it opens the camera, I receive the callback when I take the picture and if I look to the folder with the file explorer of the phone I can see the picture and also the ".nomedia" file that I created.

The thing is that I don't want the camera to store this image in the gallery of the phone, because, somehow this is "magically" ;) added to the Gallery of Android and I thought with adding the ".nomedia" file and creating the picture in a separate folder the Gallery won't scan it. The idea is that the pictures are only for internal use of the app.

Is there anyway of avoiding this? I really searched and try many different ways, but I cannot solve it.

I hope I was clear with the explanation.

Thanks in advance!


1 answers


Я нашел это решение: Прекратить сохранение фотографий с помощью Android родную камеру

Идея заключается в том, чтобы проверить, какие файлы находятся в галерее непосредственно перед съемкой и только после этого, удалите это тот, который является новым.

Это не самое чистое решение, но это работает.