I am using Content Provider to get all the music files in the device and display it in the list, however, I now do not want files from a particular folder “X” to appear in my list.
I am using this currently to get all the audio files from SD card.
private static final String[] EXTERNAL_COLUMNS = new String[] {
MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.IS_RINGTONE,
MediaStore.Audio.Media.IS_MUSIC,
"\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "\"" };
private Cursor getExternalAudioCursor(String selection,
String[] selectionArgs) {
return managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
EXTERNAL_COLUMNS, selection, selectionArgs,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
Cursor c = new MergeCursor(new Cursor[] {
getExternalAudioCursor(selection, argsArray)};
Also from Android docs, I read this…
public static final String MEDIA_IGNORE_FILENAME
Since: API Level 9 Name of the file signaling the media scanner to
ignore media in the containing directory and its subdirectories.
Developers should use this to avoid application graphics showing up in
the Gallery and likewise prevent application sounds and music from
showing up in the Music app. Constant Value: “.nomedia”
But I cannot be specific about the filenames, because I do not know them before hand.
So my question is can I do something similar with a folder, so that all its content’s do not show up in my List?
If not, then is there any other way I could do this?
You could add a .nomedia file to that folder, but that’s not really a programatic solution and you can probably only do that on the SDCARD.
Unfortunately, that would also prevent other media scanning applications from picking up any files from that folder. If nothing else, you could add it, scan, then delete it. But it’s a really ugly/hacky solution.
http://lifehacker.com/5793803/disable-media-scanning-in-specific-android-directories-by-creating-a-nomedia-file
Edit: Apparently, folders that start with a period become hidden to the system. Again, it doesn’t seem like the best idea.
The premise of temporarily modifying a directory/adding a .nomedia file, scanning, then deleting it doesn’t seem all that evil, but what if your app crashes before you’ve had a chance to reset the files/folders back to their original states? If an application modified my directory and now other applications can no longer function properly (possibly), I would be a rather upset user.
These solutions seem like they are geared towards consumers/users rather than developers.