Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

[[ Bug 22763 ]] Fix resizing mobilePickPhoto for API Level < 24 #7368

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

livecodepanos
Copy link
Contributor

@livecodepanos livecodepanos commented Jun 4, 2020

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 uses another constructor, that is available in older APIs as well.

Closes https://quality.livecode.com/show_bug.cgi?id=22763

@livecodepanos livecodepanos added this to the 9.6.1-rc-1 milestone Jun 4, 2020
@runrevmark runrevmark changed the title [22763] Fix mobilePickPhoto with width and height params in Android 5 and 6 [[ Bug 22763 ]] Fix resizing mobilePickPhoto for API Level < 24 Jun 10, 2020
Copy link
Contributor

@runrevmark runrevmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the title of the PR, could you make the main commit message title match it please :)

InputStream t_exif_in = ((LiveCodeActivity)getContext()).getContentResolver().openInputStream(t_photo_uri);

ExifInterface t_exif = new ExifInterface(t_exif_in);
ExifInterface t_exif = new ExifInterface(t_photo_uri.getPath());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned that this will break on newer Android versions. Android versions >= 7 (IIRC - API Level 24 by any chance - that's where the new constructor was introduced) are more strict about how apps access files.

In this case the input could be either a Uri from picking from a library, or presumably a temp file from taking a photo.

Can you confirm that all aspects of mobilePickPhoto still work with this change in both Andoid6 and 7+?

@livecodepanos livecodepanos force-pushed the bugfix-22763 branch 2 times, most recently from 5467444 to 731c89a Compare June 10, 2020 16:25
@livecodepanos livecodepanos requested a review from runrevmark June 10, 2020 16:33

ExifInterface t_exif = new ExifInterface(t_exif_in);

ExifInterface t_exif;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the rest of this file is indent with tabs, make sure the changes are

There appears to already be an InputStream created for the photo above (t_in) so we can resue that here. This means that this code can be a little more compact. I suggest:

/* 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_exit = new ExifInterface(t_in);
}
else
{
    t_exif = new ExifInterface(t_photo_uri.getPath());
}

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.
@runrevmark
Copy link
Contributor

@livecode-vulcan review ok 7dafc03

@livecode-vulcan
Copy link
Contributor

💙 review by @runrevmark ok 7dafc03

livecode-vulcan added a commit that referenced this pull request Jul 2, 2020
[[ 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 uses another constructor, that is available in older APIs as well.

Closes https://quality.livecode.com/show_bug.cgi?id=22763
@livecode-vulcan
Copy link
Contributor

😎 test success 7dafc03

  • try-community-armv6-android-sdk26_ndk16r15: success
  • try-community-armv7-android-ndk16r15: success
  • try-community-arm64-android-ndk16r15: success
  • try-community-x86-android-ndk16r15: success
  • try-community-x86_64-android-ndk16r15: success
  • try-community-js-emscripten-sdk1.35: success
  • try-community-universal-ios-iphoneos13.5: success
  • try-community-universal-ios-iphonesimulator13.5: success
  • try-community-universal-mac-macosx10.9: success
  • try-community-x86-linux-debian8: success
  • try-community-x86_64-linux-debian8: success
  • try-community-x86-win32: success
  • try-community-x86_64-win32: success

@livecodepanos livecodepanos merged commit 683beca into livecode:develop-9.6 Jul 2, 2020
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
Copy link
Contributor Author

@livecodepanos livecodepanos Jul 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, using the existing InputStream t_in causes the captured pic to be rotated 90 degrees. I am wondering if this was the reason @montegoulding used a new one (i.e. the t_exif_in one) in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Yes - the reason is that we've used the t_in stream above! Oops!

So below we should do:

if (Build.VERSION....)
{
    t_in.close();
    t_in = ((LiveCodeActivity)getContext()).getContentResolver().openInputStream(t_photo_uri);
}

This will close the (now finished) original stream, and then create a new one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.