From bc30da99a7a5b6910ea0989a146e3116611e82db Mon Sep 17 00:00:00 2001 From: sreesharp Date: Thu, 15 Nov 2018 18:51:24 -0800 Subject: [PATCH] Added FileProvider support for Android --- android/src/main/AndroidManifest.xml | 11 +++++++++++ .../src/main/java/com/chirag/RNMail/RNMailModule.java | 6 +++++- android/src/main/res/xml/provider_paths.xml | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 android/src/main/res/xml/provider_paths.xml diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 914eec5..849e875 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,15 @@ + + + + + \ No newline at end of file diff --git a/android/src/main/java/com/chirag/RNMail/RNMailModule.java b/android/src/main/java/com/chirag/RNMail/RNMailModule.java index 658ce6a..493a439 100644 --- a/android/src/main/java/com/chirag/RNMail/RNMailModule.java +++ b/android/src/main/java/com/chirag/RNMail/RNMailModule.java @@ -5,6 +5,7 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.text.Html; +import android.support.v4.content.FileProvider; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; @@ -89,7 +90,10 @@ public void mail(ReadableMap options, Callback callback) { if (attachment.hasKey("path") && !attachment.isNull("path")) { String path = attachment.getString("path"); File file = new File(path); - Uri p = Uri.fromFile(file); + Uri p = FileProvider.getUriForFile( + reactContext, + reactContext.getApplicationContext() + .getPackageName() + ".provider", file); i.putExtra(Intent.EXTRA_STREAM, p); } } diff --git a/android/src/main/res/xml/provider_paths.xml b/android/src/main/res/xml/provider_paths.xml new file mode 100644 index 0000000..61248eb --- /dev/null +++ b/android/src/main/res/xml/provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file