Picking images from gallery with the following code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, PICK_FILE_RESULT_CODE);
Getting result with the following code:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FILE_RESULT_CODE) {
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
// Get the Uri of the selected file
Uri uri = data.getData();
//Using Picasso to load uri to imageView
//Image is in landscape even if it was taken in portrait
}
}
}
The code works fine for HTC and Nexus phones, but just for Samsung devices (Galaxy 5 and Galaxy 5 mini) the orientation is wrong if the photo was taken in portrait. When looking at the ExifInterface the orientation is undefined..
File imageFile = new File(uri.getPath());
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
//orientation is always 0 for samsung devices = ORIENTATION_UNDEFINED
How can I present the images correctly alternative determine the correct orientation so that I can rotate the image?