Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing hidden file .nomedia fails on internal storage

Tags:

android

I want to create .nomedia file in the internal cache directory where I will store images and tried the following..

File dir = getCacheDir();
File output = new File(dir, ".nomedia");
boolean fileCreated = output.createNewFile();

When I try this fileCreated is false and the file doesn't get created. If I used nomedia without a dot the file gets created but this is no use as the MediaScanner is looking if the .nomedia file exists.

I also tried this with a FileOutputStream and to write data in the file in case it was because I was only created an empty file but this doesn't work either.

Anyone have an idea why this could be failing?

like image 251
Azalar Avatar asked Feb 13 '11 18:02

Azalar


People also ask

What is .NOMEDIA on my phone?

A NOMEDIA file is an Android No Media file. Folders containing this file will hide media files. You're free to create and delete these files to hide or unhide content.

Where are NOMEDIA files stored?

Where are . nomedia files stored? NOMEDIA files are typically found in multimedia folders or external storage cards connected to an Android smartphone or tablet. In rare cases, they may show up on a PC or Mac that has been synced with an Android device.

How do I unhide .NOMEDIA files?

You can also use the ES File Explorer app for Android. It is a file browsing software just like My Documents in Windows. The browser makes it possible to easily view and delete the . NOMEDIA files from your smartphone, just make sure you have enabled the Show Hidden Files option on the smartphone.


1 Answers

Hmm, are you really sure that the file not already exists? Please note that you need to do an ls -a to see a file starting with a dot.

The documentation of File.createNewFile() says:

Returns true if the file has been created, false if it already exists.

If the file is not created for other reasons (i.e. security), it should throw an exception.

like image 103
Christian Gawron Avatar answered Sep 20 '22 18:09

Christian Gawron