Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide images from android gallery

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

like image 454
PPShein Avatar asked Jul 23 '13 02:07

PPShein


3 Answers

  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/

like image 180
ozbek Avatar answered Oct 17 '22 19:10

ozbek


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();
      }
   }
like image 29
Jaiprakash Soni Avatar answered Oct 17 '22 18:10

Jaiprakash Soni


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

like image 27
Harish S Avatar answered Oct 17 '22 17:10

Harish S