Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - .nomedia not working for images

Tags:

I have images, which are read from sdcard only by particular application so I want to hide it from image gallery. I have put .nomedia file in it, but this file is ignored, images are still showing in Gallery. I have put it with "." in the beginning. Still not working. Any ideas?

like image 395
Waypoint Avatar asked May 22 '12 07:05

Waypoint


2 Answers

I'm guessing you're using Android 4.0, as .nomedia functioned properly until then. The AOSP bug report for the issue explains:

MediaScanner on Android 4.0 fails to forget already-indexed files when it encounters a .nomedia file, but it does honor it if it's present on the first pass. So the workaround is to simply rename the directory. Of course you can change the name back after the next scan, if you like.

Update: I suppose the complete solution would be to actually force a media scan after renaming the directory. I haven't tried it, but something like this should do the trick:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +     Environment.getExternalStorageDirectory()))); 
like image 147
Darshan Rivka Whittle Avatar answered Sep 21 '22 14:09

Darshan Rivka Whittle


Well... I admit I'm only guessing, but since it got a +1 in the comment, I'll give it a whirl as an answer. Since this is your own app, change the image file's extension to something totally unique ".myimagefile" for instance, and see if that hides it from Android. Meanwhile you know what files to load into your own app, and how to save them.

like image 38
Yevgeny Simkin Avatar answered Sep 22 '22 14:09

Yevgeny Simkin