how to hide images from android gallery

2019-01-17 22:11发布

问题:

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."

回答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/



回答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();
      }
   }


回答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 :-)



回答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