Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileProvider should be extended rather than used directly #5

Open
sam-maverick opened this issue Apr 9, 2024 · 0 comments
Open

FileProvider should be extended rather than used directly #5

sam-maverick opened this issue Apr 9, 2024 · 0 comments

Comments

@sam-maverick
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

It came to my attention the following comment in the Android official guide:

https://developer.android.com/reference/androidx/core/content/FileProvider

It is possible to use FileProvider directly instead of extending it. However, this is not reliable and will causes crashes on some devices.

So for better compatibility, I suggest the modifications below:

diff --git a/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/MyFileProvider.java b/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/MyFileProvider.java
new file mode 100644
index 0000000..23c735c
--- /dev/null
+++ b/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/MyFileProvider.java
@@ -0,0 +1,5 @@
+package com.artirigo.fileprovider;
+
+import androidx.core.content.FileProvider;
+
+public class MyFileProvider extends FileProvider { }
diff --git a/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/RNFileProviderModule.java b/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/RNFileProviderModule.java
index a9bc7d9..8141365 100644
--- a/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/RNFileProviderModule.java
+++ b/node_modules/react-native-file-provider/android/src/main/java/com/artirigo/fileprovider/RNFileProviderModule.java
@@ -34,7 +34,7 @@ public class RNFileProviderModule extends ReactContextBaseJavaModule {
       //
       File file = new File(filepath);
       if (!file.exists()) throw new Exception("File does not exist");
-      Uri contentUri = FileProvider.getUriForFile(this.getReactApplicationContext(), authority, file);
+      Uri contentUri = MyFileProvider.getUriForFile(this.getReactApplicationContext(), authority, file);
       promise.resolve(contentUri.toString());
     } catch (Exception ex) {
       ex.printStackTrace();

This issue body was partially generated by patch-package.

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

No branches or pull requests

1 participant