作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Android getContentResolver() 在具有大量项目的 WHERE 子句中使用“IN”
我已经完全成功地实现了这个查询,它提供了所需的数据
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String projection[] = {MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.COMPOSER,
MediaStore.Audio.Media.DURATION,
// android.provider.MediaStore.Audio.Albums.ALBUM_ART,
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media._ID,};
String selection1 = MediaStore.Audio.Media.IS_MUSIC + " = 1" + " AND "
+ MediaStore.Audio.Media._ID + " IN(";
for (int i = 0; i < SongsList.size(); i++) {// songslist is an array of IDs
selection1 += "?, ";
}
selection1 = selection1.substring(0, selection1.length() - 2) + ")";
String[] selectionArgs = new String[SongsList.size()];
selectionArgs = SongsList.toArray(selectionArgs);
Cursor cursor = this.getContentResolver().query(uri, projection, selection1,
selectionArgs, null);
但是当 Items 数量很大时查询失败,
是否有替代方法可以使用 getContentResolver() 检索大量项目,而无需在 WHERE 子句中使用“IN”
最佳答案
当使用 SQL 时,处理大量 ID 的正确方法是将它们放入一个临时表中,然后将其与媒体表连接起来。但是对于内容提供商,您无权访问该数据库,因此这是不可能的。
最好的办法是检索所有行,然后忽略任何没有您的 ID 的行。
或者,逐行检索。 (这可能有太多的开销。)
(如果您需要将过滤后的结果作为实际的 Cursor
对象,请将它们放入 MatrixCursor .)
关于Android getContentResolver() 将 “IN” 与具有大量项目的 WHERE 子句一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41541891/
我是一名优秀的程序员,十分优秀!