MediaStore 从特定路径列出

MediaStore to list from specific path

我正在尝试从特定文件夹中获取 mp3 文件列表。

截至目前,我正在使用 contentResolver.query 从我的 phone 获取音乐。

像这样:

String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

        String[] projection = {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.ARTIST,
                MediaStore.Audio.Media.TITLE,
                MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.DISPLAY_NAME,
                MediaStore.Audio.Media.DURATION
        };

        ContentResolver contentResolver = context.getContentResolver();
        cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,projection, selection,null,null);

我正在寻找仅扫描特定文件夹的解决方案。我如何使用 contentResolver 执行此操作?

谢谢!

终于自己弄明白了。希望对其他人有帮助。

而不是这个:

cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);

我用过这个:

cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,MediaStore.Audio.Media.DATA + " like ? ",
                new String[] {"%MyMusicFolder%"},  null);