A
A
Artem2014-02-09 16:44:39
Android
Artem, 2014-02-09 16:44:39

Getting preview from different image paths in Android?

In my project, I use this code to get previews:

Cursor cursor = crThumb.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media._ID }, MediaStore.Images.Media.DATA + "='" + file.getAbsolutePath() + "'", null, null);
if (cursor != null) {
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        thumbnailBitmap = MediaStore.Images.Thumbnails.getThumbnail(crThumb, cursor.getInt(0), MediaStore.Images.Thumbnails.MINI_KIND, null);
    }
    cursor.close();

}

On my device, several different paths can lead to one image. For example, /storage/emulated/0/Download/dog.jpg , /storage/emulated/legacy/Download/dog.jpg , /sdcard/Download/dog.jpg , and /mnt/sdcard/Download/dog.jpg point to one and the same file - dog.jpg. But the code above only works fine for /storage/emulated/0/Download/dog.jpg , but doesn't work for all others (cursor.getCount()==0). How to bypass it? How to get a preview for all other paths?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sild, 2014-02-09
@Sild

redirects to the first option (by template), as a crutch option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question