Create a URI for MediaStore for a specific folder

For example, if a has two directories /sdcard/Music/Music-1 and /sdcard/Music/Music-2 , how can I build a URI to receive files in the Music-1 dir directory, for example. I can use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI to get the contents of the entire external storage, but how to do the trick only for a specific directory.

+4
source share
3 answers

Filter the path from the DATA field and create a poper SELECT WHERE according to the folder names, you can use SUBSTR in the query; -)

+3
source
 Cursor mCursor = getContentResolver().query( uri1, Selection, android.provider.MediaStore.Audio.Media.DATA + " like ? ", new String[] {str}, null); 

Instead, you may need "%"+str+"%" because "Music-1" is only part of MediaStore.Audio.Media.DATA .

+3
source

Do just that

 Cursor mCursor = getContentResolver().query(uri1, Selection, android.provider.MediaStore.Audio.Media.DATA + " like ? ", new String[] {str}, null); 
+2
source

All Articles