react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

Handle file paths and URIs for internal and external storage across Android versions

Open ThienMD opened this issue 1 year ago • 0 comments

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:

  1. It did not handle internal app storage file paths correctly.
  2. It did not use the MediaStore API 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 a File object from the file path and uses it to create the ExifInterface instance.

  • For external storage file paths/URIs:

    • On Android 10 (API level 29) and above, it uses the MediaStore API to retrieve the content URI for the file path/URI and creates the ExifInterface instance 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 File object and then creates the ExifInterface instance from the file path.

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.

ThienMD avatar Jun 18 '24 14:06 ThienMD