react-native-image-resizer
react-native-image-resizer copied to clipboard
Handle file paths and URIs for internal and external storage across Android versions
This PR addresses an issue with the getOrientationMatrix method in the ImageResizer class, which did not handle file paths and URIs correctly for both internal app storage and external storage across different Android versions, especially after the introduction of Scoped Storage changes in Android 10 (API level 29).
The existing implementation had the following limitations:
- It did not handle internal app storage file paths correctly.
- It did not use the
MediaStoreAPI to retrieve content URIs for external storage file paths/URIs on Android 10 and above, as required by the Scoped Storage changes.
This PR updates the getOrientationMatrix method to handle the following scenarios:
-
For internal app storage file paths (starting with
/data/), it directly creates aFileobject from the file path and uses it to create theExifInterfaceinstance. -
For external storage file paths/URIs:
- On Android 10 (API level 29) and above, it uses the
MediaStoreAPI to retrieve the content URI for the file path/URI and creates theExifInterfaceinstance from the content URI, adhering to the Scoped Storage changes. - On Android versions below 10, it uses the provided file path/URI directly to create a
Fileobject and then creates theExifInterfaceinstance from the file path.
- On Android 10 (API level 29) and above, it uses the
The changes ensure that the getOrientationMatrix method works correctly for various file path/URI scenarios, taking into account the Scoped Storage changes introduced in Android 10.