Construct MediaStore URI for specific folder

2020-02-06 08:24发布

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.

标签: android
3条回答
家丑人穷心不美
2楼-- · 2020-02-06 09:20
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.

查看更多
Explosion°爆炸
3楼-- · 2020-02-06 09:21

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 ;-)

查看更多
冷血范
4楼-- · 2020-02-06 09:26

Do exactly this,

Cursor mCursor = getContentResolver().query(uri1, Selection, 
            android.provider.MediaStore.Audio.Media.DATA + " like ? ", 
            new String[] {str},
            null);
查看更多
登录 后发表回答