Skip to content

Commit 4373988

Browse files
authored
Merge pull request #5 from timscott/fix-android-issues
Fixed various issue in android with multiple attachments.
2 parents 9c75f26 + ac92e5d commit 4373988

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

android/src/main/java/com/chirag/RNMail/RNMailModule.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,6 @@ public void mail(ReadableMap options, Callback callback) {
8080
ReadableArray ccRecipients = options.getArray("ccRecipients");
8181
i.putExtra(Intent.EXTRA_CC, readableArrayToStringArray(ccRecipients));
8282
}
83-
if (options.hasKey("attachments") && !options.isNull("attachments")) {
84-
ReadableArray r = options.getArray("attachments");
85-
int length = r.size();
86-
ArrayList<Uri> uris = new ArrayList<Uri>();
87-
for (int keyIndex = 0; keyIndex < length; keyIndex++) {
88-
ReadableMap clip = r.getMap(keyIndex);
89-
if (clip.hasKey("path") && !clip.isNull("path")){
90-
String path = clip.getString("path");
91-
File file = new File(path);
92-
Uri u = Uri.fromFile(file);
93-
uris.add(u);
94-
}
95-
}
96-
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
97-
}
9883

9984
if (options.hasKey("bccRecipients") && !options.isNull("bccRecipients")) {
10085
ReadableArray bccRecipients = options.getArray("bccRecipients");
@@ -110,6 +95,7 @@ public void mail(ReadableMap options, Callback callback) {
11095
if (clip.hasKey("path") && !clip.isNull("path")) {
11196
String path = clip.getString("path");
11297
File file = new File(path);
98+
file.setReadable(true, false);
11399
if (file.exists()) {
114100
uris.add(Uri.fromFile(file));
115101
}
@@ -118,12 +104,6 @@ public void mail(ReadableMap options, Callback callback) {
118104
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
119105
}
120106

121-
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.
122-
final Intent restrictIntent = new Intent(Intent.ACTION_SENDTO);
123-
Uri data = Uri.parse("mailto:[email protected]");
124-
restrictIntent.setData(data);
125-
i.setSelector(restrictIntent);
126-
127107
PackageManager manager = reactContext.getPackageManager();
128108
List<ResolveInfo> list = manager.queryIntentActivities(i, 0);
129109

@@ -145,6 +125,7 @@ public void mail(ReadableMap options, Callback callback) {
145125
try {
146126
reactContext.startActivity(chooser);
147127
} catch (Exception ex) {
128+
callback.invoke("error");
148129
}
149130

150131
}

0 commit comments

Comments
 (0)