I've been playing with android's thumbnails for a while now, and I've seen some inconsistencies that make me want to scream. My goal is to have a simple list of all Images (and a separate list for video) with the thumbnail and filename.
Device: HTC Evo (fresh from Google I/o)
First off: http://androidsamples.blogspot.com/2009/06/how-to-display-thumbnails-of-images.html
That code doesn't seem to work at all, thumbnails are duplicated... some with the "mirror" effect and some without. Also some won't load and just display a black square. I've tried rebuilding the thumbnails by deleting the "alblum thumbs" directory from the SD card. HTC's gallery application seem to show everything fine.
This approach seems to work:
Bitmap thumb = MediaStore.Images.Thumbnails.getThumbnail(
getContentResolver(),
id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
imageView.setImageBitmap(curThumb);
where id is the original images id and imageView is some image view. This is great! But, strangely, way too slow to be used inside a SimpleViewBinder. Next approach:
String [] proj = {MediaStore.Images.Thumbnails._ID};
Cursor c = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
proj, MediaStore.Images.Thumbnails.IMAGE_ID + "=" +id ,
null, null);
if (c != null && c.moveToFirst()) {
Uri thumb = Uri.withAppendedPath(mThumbUri,c.getLong(0)+"");
imageView.setImageURI(thumb);
}
I should explain that I feel the needed WHERE condition is required because there doesn't seem to be any guarantee that your uri will have the same ID for both a thumbnail and its parent image. This works for all of the current images, but as soon as I start adding pictures with the camera they show up as blank! Debugging shows a dreaded:
SkImageDecoder::Factory returned null
error and the URI is returned as invalid. These are the same images that work with the previous call. Can anyone either catch my logical failure or point me to some working code?