public static void queryPhotoByBucket(Context context, String bucketId,
ArrayList<UploadItem> photoItems) {
photoItems.clear();
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.DATE_ADDED,
MediaStore.Images.Media._ID };
String selection = MediaStore.Images.ImageColumns.BUCKET_ID
+ " = '" + bucketId + "' and "
+ MediaStore.Images.ImageColumns.DATE_TAKEN + " >= 0";
if (u != null) {
c = context.getContentResolver().query(u, projection, selection,
null, null);
}
if ((c != null) && (c.moveToFirst())) {
do {
photoItems.add(new UploadItem(c.getString(0),
new ImmutableDate(
Long.parseLong(c.getString(1) == null ? c
.getString(2) : c.getString(1))), c
.getLong(3)));
} while (c.moveToNext());
}
c.close();
getThumbs(context, photoItems);
}
private static void getThumbs(Context context,
ArrayList<UploadItem> photoItems) {
for (int i = 0; i < photoItems.size(); i++) {
UploadItem item = photoItems.get(i);
getThumb(context, item);
}
}
private static long lastPhotoId = -1;
private static void getThumb(Context context, UploadItem item) {
Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
context.getContentResolver(), item.getPhotoId(),
MediaStore.Images.Thumbnails.MINI_KIND, null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
String thumbPath = cursor.getString(cursor
.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
item.setThumbPath(thumbPath);
} else {
if (lastPhotoId == item.getPhotoId()) {
item.setThumbPath(item.getPhotoPath());
} else {
Thumbnails.getThumbnail(context.getContentResolver(),
item.getPhotoId(), Thumbnails.MINI_KIND, null);
lastPhotoId = item.getPhotoId();
getThumb(context, item);
}
}
}
を役に立てば幸い