我正在使用 CursorJoiner 加入 Media.Image 和 Thumbnail 表,以便从特定专辑中选择缩略图,而不使用实际的 SQL。
但是,Media.Image 表和相应的 Thumbnails 表中的数据似乎不匹配。缩略图总是比实际图像少(但我知道缩略图存在于磁盘上)。
我正在使用以下代码:
public ThumbnailSelector(Context context) {
mContext = context;
}
public List<LocalThumbnail<Integer>> getSqlThumbnailsFromBucket(String bucket) {
return null;
}
protected Cursor getImageMediaCursor(String bucket) {
String[] projection = { Media._ID, Media.BUCKET_DISPLAY_NAME };
String selection = String.format("(%s='%s')", Media.BUCKET_DISPLAY_NAME, bucket);
Cursor cursor = mContext.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, projection,
selection, null, Media._ID + " ASC");
cursor.moveToFirst();
return cursor;
}
protected Cursor getImageThumbnailCursor() {
String[] projection = { Thumbnails.IMAGE_ID, Thumbnails.DATA };
String selection = String.format("%s=%d", Thumbnails.KIND, Thumbnails.MINI_KIND);
Cursor cursor = mContext.getContentResolver().query(Thumbnails.EXTERNAL_CONTENT_URI,
projection, selection, null, Thumbnails.IMAGE_ID + " ASC");
cursor.moveToFirst();
return cursor;
}
public List<LocalThumbnail<Integer>> getThumbnailsFromBucket(String bucket) {
List<LocalThumbnail<Integer>> thumbnails = new ArrayList<LocalThumbnail<Integer>>();
Cursor imageThumbnailCursor = getImageThumbnailCursor();
Cursor imageMediaCursor = getImageMediaCursor(bucket);
CursorJoiner joiner = new CursorJoiner(imageMediaCursor, new String[] { Media._ID },
imageThumbnailCursor, new String[] { Thumbnails.IMAGE_ID });
int idColumnIndex = imageThumbnailCursor.getColumnIndex(Thumbnails.IMAGE_ID);
int dataColumnIndex = imageThumbnailCursor.getColumnIndex(Thumbnails.DATA);
for (CursorJoiner.Result joinerResult : joiner) {
switch (joinerResult) {
case RIGHT: {
break;
}
case LEFT: {
break;
}
case BOTH:
thumbnails.add(new LocalThumbnail<Integer>(imageThumbnailCursor
.getInt(idColumnIndex), "file://"
+ imageThumbnailCursor.getString(dataColumnIndex)));
break;
}
}
imageThumbnailCursor.close();
imageMediaCursor.close();
return thumbnails;
}
有谁知道为什么会发生这种不匹配?