-
Notifications
You must be signed in to change notification settings - Fork 222
[[ Bug 22763 ]] Fix resizing mobilePickPhoto for API Level < 24 #7368
Conversation
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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+?
5467444
to
731c89a
Compare
|
||
ExifInterface t_exif = new ExifInterface(t_exif_in); | ||
|
||
ExifInterface t_exif; |
There was a problem hiding this comment.
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.
731c89a
to
7dafc03
Compare
@livecode-vulcan review ok 7dafc03 |
💙 review by @runrevmark ok 7dafc03 |
[[ 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
😎 test success 7dafc03
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This patch ensures that calling
mobilePickPhoto
with width and height params works in older Android versions too. Previously, a constructor forExifInterface
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