Skip to content

Commit

Permalink
Merge pull request #5 from timscott/fix-android-issues
Browse files Browse the repository at this point in the history
Fixed various issue in android with multiple attachments.
  • Loading branch information
adamski authored Dec 28, 2017
2 parents 9c75f26 + ac92e5d commit 4373988
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions android/src/main/java/com/chirag/RNMail/RNMailModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> uris = new ArrayList<Uri>();
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");
Expand All @@ -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));
}
Expand All @@ -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:[email protected]");
restrictIntent.setData(data);
i.setSelector(restrictIntent);

PackageManager manager = reactContext.getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(i, 0);

Expand All @@ -145,6 +125,7 @@ public void mail(ReadableMap options, Callback callback) {
try {
reactContext.startActivity(chooser);
} catch (Exception ex) {
callback.invoke("error");
}

}
Expand Down

0 comments on commit 4373988

Please sign in to comment.