how to hide images from android gallery

房东的猫 提交于 2019-11-27 19:18:21

问题


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



来源:https://stackoverflow.com/questions/17800491/how-to-hide-images-from-android-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!