Reputation: 2843
I have an app that I wrote to upload images to my server, which worked great on a droidx running android 2.3.4 and two different simulators running android 4.0.3. However, when I try to run it on an Asus ee Pad Transformer (running 4.0.3), it always tells me that there are 0 items in MediaStore.Images.Thumbnails.
String[] projection = {MediaStore.Images.Thumbnails._ID};
cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Thumbnails.IMAGE_ID);
Log.d("Info","There are " + cursor.getCount() + " items");
There should be 6 showing up, 5 from the camera and 1 that I downloaded off the internet. Earlier code that just gets images rather than thumbnails tells me that there are 5 images from the camera, so I know that code is working.
String[] projection = {MediaStore.Images.Media._ID};
cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
"Camera",
null,null);
Log.d("Info","There are " + cursor.getCount() + " images");
These images all show up when I open the gallery app. I've also tried clearing the Media Storage app and rebooting the device to see if that would help, but it didn't. At this point, I'm very confused, especially since this exact same code worked on the phone and simulators.
Upvotes: 3
Views: 4016
Reputation: 4712
OK, found it.
When you have the image id you get get it's thumbnail using:
MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), imageID, MediaStore.Images.Thumbnails.MINI_KIND, null);
this will return the Bitmap without loading the full image.
Upvotes: 4
Reputation: 2843
I created a utilities class that will create and return the thumbnails for images and videos if you pass it the uri for the image / video you want to get.
package Utilities;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.provider.MediaStore;
public class AndroidUtils
{
public static final int THUMBNAIL_SIZE = 128;
public static Bitmap GetImagePreview(String uri)
{
return ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(uri), THUMBNAIL_SIZE, THUMBNAIL_SIZE);
}
public static Bitmap GetVideoPreview(String uri)
{
return ThumbnailUtils.createVideoThumbnail(uri, MediaStore.Images.Thumbnails.MICRO_KIND);
}
}
Upvotes: 0