We're developing an app which allows the user to take a photo or pick one from the gallery. We're using the Android Crop library for this.
When testing on Android devices which aren't from Samsung the photo appears okay. However, all photos taken on Samsung devices appear rotated 90 degrees.
What is happening here? How can I make the photos appear in the proper rotation?
Here is some example code.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode == RESULT_OK) {
/*if (requestCode == SelectItensOption.MY_SCHOOL.ordinal()) {
int selectedIndex = data.getIntExtra("selectedIndex",0);
if (selectedIndex < BusinessModel.getInstance().getSchools().size()){
updateSchool(BusinessModel.getInstance().getSchools().get(selectedIndex));
}
} else if (requestCode == SelectItensOption.MY_PROFESSION.ordinal()) {
int selectedIndex = data.getIntExtra("selectedIndex",0);
if (selectedIndex < BusinessModel.getInstance().getProfessions().size()){
updateProfession(BusinessModel.getInstance().getProfessions().get(selectedIndex));
}
} else if(requestCode == SelectItensOption.MY_GENDER.ordinal()) {
int selectedIndex = data.getIntExtra("selectedIndex",0);
if (selectedIndex == 0) {
updateGender(Sex.F);
} else {
updateGender(Sex.M);
}
} else */if (requestCode == Crop.REQUEST_PICK) {
beginCrop(data.getData());
} else if (requestCode == Crop.REQUEST_CROP) {
uploadPhoto(Crop.getOutput(data),currentManagePhotoOrder);
} else if (requestCode == CODE_CAPTURE_IMAGE) {
beginCrop(captureImageFileUri);
} else if (requestCode == SELECTITEM_RESULT_CODE) {
updateUserInfo();
}
}
}
private void beginCrop(Uri source) {
Uri destination = Uri.fromFile(new File(mActivity.getCacheDir(), "image"+currentManagePhotoOrder));
Crop.of(source, destination).asSquare().start(mActivity);
}
@Override
public void managePhoto(int order) {
currentManagePhotoOrder = order;
// captureImageFileUri = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".my.package.name.provider", getOutputMediaFile());
// captureImageFileUri = Uri.fromFile(getOutputMediaFile());
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
captureImageFileUri = FileProvider.getUriForFile(mActivity,
"com.theluckymountain.spider",
photoFile);
}
try {
Photo photo = getUserProfile().getPhotos().get(order-1);
ManagePhotoPresenter.showAlert(mActivity,photo,captureImageFileUri,(ManagePhotoCallback) this);
} catch (Exception e) {
ManagePhotoPresenter.showAlert(mActivity,null,captureImageFileUri,(ManagePhotoCallback)this);
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = mActivity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
// mCurrentPhotoPath = image.getAbsolutePath();
return image;
}