1

I have an application which has loads of pictures. The total picture is saved in an SD card due to large number of picture. The main problem is that the pictures are available in gallery. I want a way to hide the picture from the gallery but must be available for my application.

I did put " . " in front of the file name to make it hidden but the images were not displayed in may application also!

Anyone.. help.. please

thanks..

  • I think android searches images by the extension. Try suffixing the images you want to hide by a unique word like ".pix" or initials of your app. – rahul Aug 27 '12 at 12:03

5 Answers5

3

Gallery handles all media files it knows about, so if you want it to stay away of your assets you got two solutions. First, add .nomedia file to the folder with your images, and Gallery should skip it (most image viewers would honor .nomedia, yet there's no guarantee). Other solution is to use some own, proprietary file format, so Gallery or other tools won't be able to process it. I'd recomment .nomedia if that's sufficient solution.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • [Here](http://stackoverflow.com/questions/10697276/android-nomedia-not-working-for-images) it was suggested changing the file extension should also work pretty well. – harism Aug 27 '12 at 11:58
  • @harism: I did use ".nomedia" but the images weren't displayed in my application! – invalideUserName Aug 27 '12 at 12:03
  • 2
    changing file extension is a weak idea, because it is not guaranteed that media viewer would even take a look at it (sure, it's is simplier to do that but...). Many viewers try to figure file format by reading file header and trying to find out if it is known one. It's like expecting *.apk to being secure because it is not named *.zip (while it is in fact regular zip archive). So `.nomedia` makes more sense than changing file name to be "cryptic" – Marcin Orlowski Aug 27 '12 at 12:05
  • @godsmAsh `.nomedia` just simply tells Gallery (and other apps) "there is no media in this folder. do not bother scanning". And that's it. You still can put media files there and `.nomedia` will not make it useless. It's just like road sign "do not speed". You should obey, but still can speed if you dare. – Marcin Orlowski Aug 27 '12 at 12:06
  • @WebnetMobile.com: in my app I do have a gallery. I want the images to be displayed in my gallery and not in the phone gallery. But when i use .nomedia, the images are not displayed in my gallery either! – invalideUserName Aug 27 '12 at 12:20
1

Add .nomedia file into the image folder. The important thing is that, the folder should be empty, when you add .nomedia file. If the folder contains some images before adding '.nomedia' file, the gallery will not hide those images, and it will hide the images added after '.nomedia' file. So The first file added to the image folder should be '.nomedia'.

Hope dis will help you

Thankx,

Shibin Francis
  • 482
  • 6
  • 18
1

This line of code can add the .nomedia file in your directory and makes your images hidden from the gallery

String NOMEDIA=" .nomedia";

File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir"); if(Folder.mkdir()) { nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA); if(!nomediaFile.exists()){ nomediaFile.createNewFile(); } }

sharath yadhav
  • 546
  • 5
  • 5
0

i think the place where you save the images matter, try to save them into application cache directory, or files directory.

you can get access to cache directory using : getCacheDir() in your activity. and your files directory: getFilesDir()

these two directories must not be visible or accessible to any other applications expect your application,

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
0

I used assets to accomplish this in my app.

jeffgzx9
  • 269
  • 1
  • 6