Manish Karena Manish Karena - 5 months ago 15
Android Question

Prevent showing hidden files and folder to gallery in android

I am creating an project for hiding files and folder.I am able to hide folder and file from file system with below code,but it show on gallery.is their any way to prevent file and folder to showing in gallery.

My code for hiding any file is:

public static void hideFile(File file){
File dstFile = new File(file.getParent(), "." + file.getName());
file.renameTo(dstFile);
}


Please help me to solve this issue.
Thanks.

Answer

Since Gallary app is meant to show all image/media files, you can skip it accesing your files by creating .nomedia folder.

Next, place all your files, that you are planning to hide, in this folder.

.nomedia is a hint to Gallery (and other similar apps) there is no media accessible in the folder to show.

One more related point is that If the folder already contains some images before adding '.nomedia' file, the gallery will not hide those images.