From ac92e5d8468aaebeaa6517a896789c485dcfd3d0 Mon Sep 17 00:00:00 2001 From: Tim Scott Date: Thu, 28 Dec 2017 13:52:59 -0600 Subject: [PATCH] Fixed various issue in android with multiple attachments. --- .../java/com/chirag/RNMail/RNMailModule.java | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/android/src/main/java/com/chirag/RNMail/RNMailModule.java b/android/src/main/java/com/chirag/RNMail/RNMailModule.java index ded5476..200a81e 100644 --- a/android/src/main/java/com/chirag/RNMail/RNMailModule.java +++ b/android/src/main/java/com/chirag/RNMail/RNMailModule.java @@ -80,21 +80,6 @@ public void mail(ReadableMap options, Callback callback) { ReadableArray ccRecipients = options.getArray("ccRecipients"); i.putExtra(Intent.EXTRA_CC, readableArrayToStringArray(ccRecipients)); } - if (options.hasKey("attachments") && !options.isNull("attachments")) { - ReadableArray r = options.getArray("attachments"); - int length = r.size(); - ArrayList uris = new ArrayList(); - for (int keyIndex = 0; keyIndex < length; keyIndex++) { - ReadableMap clip = r.getMap(keyIndex); - if (clip.hasKey("path") && !clip.isNull("path")){ - String path = clip.getString("path"); - File file = new File(path); - Uri u = Uri.fromFile(file); - uris.add(u); - } - } - i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); - } if (options.hasKey("bccRecipients") && !options.isNull("bccRecipients")) { ReadableArray bccRecipients = options.getArray("bccRecipients"); @@ -110,6 +95,7 @@ public void mail(ReadableMap options, Callback callback) { if (clip.hasKey("path") && !clip.isNull("path")) { String path = clip.getString("path"); File file = new File(path); + file.setReadable(true, false); if (file.exists()) { uris.add(Uri.fromFile(file)); } @@ -118,12 +104,6 @@ public void mail(ReadableMap options, Callback callback) { i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } - i.setType(null); // If we're using a selector, then clear the type to null. I don't know why this is needed, but it doesn't work without it. - final Intent restrictIntent = new Intent(Intent.ACTION_SENDTO); - Uri data = Uri.parse("mailto:?to=some@email.com"); - restrictIntent.setData(data); - i.setSelector(restrictIntent); - PackageManager manager = reactContext.getPackageManager(); List list = manager.queryIntentActivities(i, 0); @@ -145,6 +125,7 @@ public void mail(ReadableMap options, Callback callback) { try { reactContext.startActivity(chooser); } catch (Exception ex) { + callback.invoke("error"); } }