Wonton Wonton - 7 months ago 45
Android Question

Samsung Galaxy S7 show device photos rotated

I've developed an android app that shows in an adapter all photos the user has in its device.

This is the code I'm using to read the photos:

Cursor photos;
String pictureCols[] = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };
String order = Media.DATE_ADDED + " DESC";
photos = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, pictureCols, null, null, order);

And inside the adapter this is the code I use to show them:

public View getView(final int position, View convertView, ViewGroup parent)

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
gridView = inflater.inflate(R.layout.photo_item, null);
gridView = (View) convertView;

photoIV = (SquareImageView)gridView.findViewById(R.id.photo);

long photoId = photos.getLong(0);
String thumbURL = "file://"+photos.getString(1);
String thumbCols[] = { MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.DATA };
Cursor thumbCursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(context.getContentResolver(), photoId, Thumbnails.MINI_KIND, thumbCols);
if(thumbCursor.getCount() > 0) {
thumbURL = "file://"+thumbCursor.getString(1);

mImageOptions = new DisplayImageOptions.Builder()

ImageLoader.getInstance().displayImage(thumbURL, photoIV, mImageOptions);

return gridView;

This code is working ok on all devices I've tested so far but some users with Samsung Galaxy S7 have reported that most of their photos are shown rotated. I cannot find any documentation related to this issue in S7. Has S7 changed something related to this? Should I read the photos in a different way to get their correct orientation? This code has been working for a long time in a lot of devices.



If you use an image-loading library, and you care about EXIF orientation headers, choose an image-loading library that applies those headers for you (e.g., Picasso, at least for local images). This may require some sort of an opt-in call (e.g., considerExifParams(true), per your comment).

Not all images will have an EXIF orientation header. It depends on whether it is a photo, what sort of camera hardware took the photo, whether the camera app that took the photo rotated the image for you, etc.