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?
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? 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With