4

For example if a have two directories /sdcard/Music/Music-1 and /sdcard/Music/Music-2 how can I construct a URI to get the files in Music-1 dir for example. I can use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI to get the content of all external storage but how to do the trick only for specific dir.

edgerunner
  • 14,873
  • 2
  • 57
  • 69
Mojo Risin
  • 8,136
  • 5
  • 45
  • 58

3 Answers3

3

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

Mutix
  • 4,196
  • 1
  • 27
  • 39
3
Cursor mCursor = getContentResolver().query(
                   uri1, Selection, 
                   android.provider.MediaStore.Audio.Media.DATA + " like ? ", 
                   new String[] {str}, null);

You might need to use "%"+str+"%" instead, because "Music-1" is just part of the MediaStore.Audio.Media.DATA.

edgerunner
  • 14,873
  • 2
  • 57
  • 69
Junzi
  • 81
  • 1
  • 3
2

Do exactly this,

Cursor mCursor = getContentResolver().query(uri1, Selection, 
            android.provider.MediaStore.Audio.Media.DATA + " like ? ", 
            new String[] {str},
            null);
Shogun
  • 84
  • 6
dhaiwat
  • 21
  • 1