how to hide images from android gallery

16,992

Solution 1

  1. Add ".nomedia" file. Did not work? Try the second option.

  2. Save your files to a folder that starts with ".", e.g., /sdcard/.myimages/

Solution 2

You can create .nomedia file using this code:
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();
      }
   }

Solution 3

I found a simple way(I think so).

Create a folder in 'Android' folder(where data & obb folders are present) and put your media(pics,videos, etc.,) in the folder you've created.

Gallery app ignores that 'Android' folder. Simple :-)

Solution 4

its so late and i know other answers are complete but i think putting .nomedia file makes all pictures in that particular folder hidden :

just change extension of image file programmatically and this way gallery cant detect it as an image . eg if your image is "pic1.jpg" rename it to "pic1.aaa"; and when you want show it again rename it again

Share:
16,992

Related videos on Youtube

PPShein
Author by

PPShein

Updated on June 04, 2022

Comments

  • PPShein
    PPShein almost 2 years

    One part of my current project is downloading images from URL then saving to SDCard. But the problem is all of saved images in sdcard is displayed in android gallery page. What I want is "I don't want all of my saved images in android gallery."

  • PPShein
    PPShein almost 11 years
    Add ".nomedia" in /sdcard/myapps/ folder? And how can I get ".nomedia" file?
  • ozbek
    ozbek almost 11 years
    Just create one, an empty file :)
  • Odaym
    Odaym over 9 years
    This doesn't work man. Not the first option, not the second option, not even creating the files with prefix "."
  • ozbek
    ozbek over 9 years
    @Odaym: This doesn't work is a very vague claim. How exactly it is not working? What steps did you take? Did you verify that you are not seeing old cached images?
  • Odaym
    Odaym over 9 years
    Doesn't work meaning that the images still show up after having created the directory with a "." prefix, creating the ".nomedia" file inside that directory and even creating the images with the "." prefix. All after triggering a rescan of media. Saw this too code.google.com/p/android/issues/detail?id=24162
  • nicolas asinovich
    nicolas asinovich about 6 years
    its perfect solution!