how to hide images from android gallery

2019-01-17 21:50发布

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

4条回答
冷血范
2楼-- · 2019-01-17 22:24

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();
      }
   }
查看更多
Summer. ? 凉城
3楼-- · 2019-01-17 22:30

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楼-- · 2019-01-17 22:33
  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/

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-17 22:36

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

查看更多
登录 后发表回答