I have a String URL pointing to an image stored on the external storage of my device:
String imageUrl = "/storage/emulated/0/DCIM/100MEDIA/IMAG0823.jpg"
I want to get query the MediaStore
to get the thumbnail for this image. This is what I do right now:
private String getImageThumbnailPath(Context ctx, String imageUrl){
Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnails(
ctx.getContentResolver(), Uri.fromFile(new File(imageUrl)),
MediaStore.Images.Thumbnails.MICRO_KIND,
null);
String url = "";
if( cursor != null && cursor.getCount() > 0 ) {
cursor.moveToFirst();
url = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) );
cursor.close();
}
return url;
}
However, calling this method and printing it's content shows nothing (the cursor is empty).
How do I query the MediaStore
for the thumbnail url associated with my image URL?
Edit
I've also tried to parse the Uri directly from the image URL, as so:
Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnails(
ctx.getContentResolver(), Uri.parse(imageUrl),
MediaStore.Images.Thumbnails.MINI_KIND,
null);
But the result is the same.
Uri.fromFile(new File(imageUrl))
/storage/emulated/0/DCIM/100MEDIA/IMAG0823.jpg
@dieter_hSystem.out.println(Uri.fromFile(new File(imageUrl)));
isfile:///storage/emulated/0/DCIM/100MEDIA/IMAG0823.jpg