Android tricks – Hide a folder from the Gallery app

Here is a small trick for preventing a folder from appearing in the Gallery application:

File path = new File("path\to\your\folder");
File file= new File(path,".nomedia");
if (!file.exists()) {
try {
} catch (IOException e) {
view raw hosted with ❤ by GitHub

Code description:

The general idea is really simple. We just have to create an empty file with the name ‘.nomedia’. That’s all! And that’s exactly what we want to do with the code snippet above. When the media scanner detects the .nomedia file, the folder is just being skipped by the OS and thus it wont be visible from the Gallery application.

Why do we need it?!

The main reason for hiding a folder from the Gallery application is… well… because you just want that particular folder to remain hidden! Sometimes you have to cache images or any other media files and you usually store them in a folder. But the Gallery application is very good in finding directories which contain media files and so your folder appears in the Gallery app. And you will agree with me that it’s not a good idea to show the user all your dirty and nasty hacks, transformations and changes you had made to the media files used by your application. Thus, hiding such folders suddenly seems beneficial.


Feel free to share, comment & give your opinion on the topic!
And only if you really REALLY liked the article, you can buy me a cup of coffee! Otherwise, don’t do it! Donate $1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s