1

Working with images on Android is like getting crazy. For a few hours I try to get all images from phone and show them into list (RecyclerView).

And then when user taps on the image, it should open a new full screen activity to display high resolution image.

I have search for a lot of tutorials on Google, but all of them seems too old and not complete at all.

Can anyone explain me how to solve this? Or link to any newer tutorial on this would be great.

My guess is that I should query MediaStore for Thumbnails and then display images in list.

Something like this:

 private void getAllImages(){

    String[] projection = {MediaStore.Images.Media._ID};

    String orderBy = MediaStore.Images.ImageColumns._ID + " DESC";         // Create the cursor pointing to the SDCard
    cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection, // Which columns to return
            null,       // Return all rows
            null,
            orderBy);
    // Get the column index of the Thumbnails Image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
}

But how I could get full resolution images, when user taps on the image in the list?

And why a lot of thumbnails has wrong orientation?

Zookey
  • 2,637
  • 13
  • 46
  • 80
  • First, `managedQuery()` has been deprecated for over four years. Please use something else, like a `CursorLoader`. Second, to get the `Uri` to the actual image, I would assume that you append the `_ID` to `MediaStore.Images.Media.EXTERNAL_CONTENT_URI`, and use that `Uri` with your favorite image loading library (e.g., Universal Image Loader). Third, the thumbnails are probably made of photos that themselves are in the "wrong orientation", using EXIF headers to tell viewer software to rotate the images. Even if the thumbnails have the headers, that info is lost when Android reads in the bitmap. – CommonsWare Jul 19 '15 at 23:46
  • Thanks for the great feedback. Currently I am using Facebook Fresco lib, and they have option to auto rotate images, but it seems that is not working properly with these thumbnails. Any good tutorial on Cursor Loader for images? – Zookey Jul 19 '15 at 23:49
  • "and they have option to auto rotate images, but it seems that is not working properly with these thumbnails" -- it's possible that the logic for generating the thumbnails themselves does not take the orientation into account. "Any good tutorial on Cursor Loader for images?" -- I have not gone looking for a tutorial. FWIW, [here is a sample app](https://github.com/commonsguy/cw-omnibus/tree/master/RecyclerView/VideoList) that demonstrates `CursorLoader`, `RecyclerView`, and `MediaStore`, but it is for showing a list of videos with thumbnails, not images. Still, it may give you some ideas. – CommonsWare Jul 19 '15 at 23:51
  • Thanks very much, I will try it tomorrow, since here is very late, and if this helps I will notify you to add comment so I can accept it. – Zookey Jul 19 '15 at 23:55

0 Answers0