2

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");
    folder.mkdirs();
    File nomedia = new File(folder,".nomedia");
    try{
        nomedia.createNewFile();
    }catch (IOException e){
        e.printStackTrace();
        Log.e("error", e.getMessage());
    }

    File file = new File(folder,"image.jpeg");
    try {
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    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!

Kuu
  • 117
  • 1
  • 12
  • I know this is probably not helpful. But I encountered the same problem a while ago and had to give up. If I remember correctly one way I tried was to move the picture into app-private storage and that prevented the gallery from showing it, but that also prevented automatic thumbnail creation. – Jan-Philipp Niewerth Jun 26 '12 at 22:52
  • try adding a period '.' to the front of the folder that you are storing the picture in. For instance in your example try switching to ".folder" as the name of your directory. Also what device are you testing on? – FoamyGuy Jun 26 '12 at 23:35
  • I tired but that doesn't help @Tim , I'm using the Galaxy S Plus, but I also have the same problem in the HTC Wildfire. – Kuu Jun 27 '12 at 11:41

1 Answers1

3

I found this solution: Stop saving photos using Android native camera

The idea is to check which files are in the gallery just before taking the picture and just after it, delete that one that is new.

It's not the cleanest solution but it works.

Community
  • 1
  • 1
Kuu
  • 117
  • 1
  • 12