From 7dafc033893bcefbd0e2653029f3b021a201d46d Mon Sep 17 00:00:00 2001 From: livecodepanos Date: Thu, 11 Jun 2020 14:56:15 +0300 Subject: [PATCH] [[ Bug 22763 ]] Fix resizing mobilePickPhoto for API Level < 24 This patch ensures that calling mobilePickPhoto with width and height params works in older Android versions too. Previously, a constructor for "ExifInterface" was used, that was available in API 24+ (Android 7+). This patch checks the Android version of the device and uses a different constructor on Android < 7. --- docs/notes/bugfix-22763.md | 1 + engine/src/java/com/runrev/android/Engine.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 docs/notes/bugfix-22763.md diff --git a/docs/notes/bugfix-22763.md b/docs/notes/bugfix-22763.md new file mode 100644 index 00000000000..f93573fb19d --- /dev/null +++ b/docs/notes/bugfix-22763.md @@ -0,0 +1 @@ +# Ensure mobilePickPhoto with width and height params works on older Android versions diff --git a/engine/src/java/com/runrev/android/Engine.java b/engine/src/java/com/runrev/android/Engine.java index 36363086ef9..57916e56c9b 100644 --- a/engine/src/java/com/runrev/android/Engine.java +++ b/engine/src/java/com/runrev/android/Engine.java @@ -2232,9 +2232,18 @@ else if (resultCode == Activity.RESULT_OK) float t_width = t_bitmap.getWidth(); float t_height = t_bitmap.getHeight(); - InputStream t_exif_in = ((LiveCodeActivity)getContext()).getContentResolver().openInputStream(t_photo_uri); - - ExifInterface t_exif = new ExifInterface(t_exif_in); + /* In API Level >= 24, you have to use an input stream to make sure that access + * to a photo in the library is granted. Before that you can just open the photo's + * file direct. */ + ExifInterface t_exif; + if (Build.VERSION.SDK_INT >= 24) + { + t_exif = new ExifInterface(t_in); + } + else + { + t_exif = new ExifInterface(t_photo_uri.getPath()); + } int t_orientation = t_exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);