gpt4 book ai didi

android - Multiple SelectionArgs - 查询 mediaStore

转载 作者:行者123 更新时间:2023-11-29 17:58:58 24 4
gpt4 key购买 nike

我正在尝试显示特定文件夹中的音频文件。文件夹由用户选择并添加到 arraylist,因此 arraylist 是动态的。现在,当我查询多个文件夹时,mediaStore 不会返回任何结果。我认为问题出在我的选择上。我知道 selectionArgs 中的项目数量应该与选择中的 ? 匹配,因此我创建了一个函数来执行此操作,但运气不佳。希望你们能帮助我。谢谢!

下面是代码:

    String[] whereVal;
String selection;

Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;



String[] folderPaths = storage.loadFolderPaths().toArray(new String[storage.loadFolderPaths().size()]);
selection = MediaStore.Audio.Media.DATA +" IN (" + makePlaceholders(folderPaths.length) + ")" ;
whereVal = folderPaths;


String[] projection = {MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM_ID};
Cursor cursor = getActivity().getContentResolver().query(uri, projection, selection, whereVal, null);



private String makePlaceholders(int len) {

StringBuilder sb = new StringBuilder(len * 2 - 1);
sb.append("?");
for (int i = 1; i < len; i++)
sb.append(",?");
Log.e("len: ", String.valueOf(len));
Log.e("Selection: ",sb.toString());
return sb.toString();

}

最佳答案

除了我的评论:

            // strip trackname
path = path.substring(path.lastIndexOf("/")+1,path.length());
String where = MediaStore.Audio.Media.DATA + " LIKE " + "\'%" +path+"%\'";

关于android - Multiple SelectionArgs - 查询 mediaStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48563470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com