forked from chirag04/react-native-mail
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from timscott/fix-android-issues
Fixed various issue in android with multiple attachments.
- Loading branch information
Showing
1 changed file
with
2 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
@@ -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:[email protected]"); | ||
restrictIntent.setData(data); | ||
i.setSelector(restrictIntent); | ||
|
||
PackageManager manager = reactContext.getPackageManager(); | ||
List<ResolveInfo> 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"); | ||
} | ||
|
||
} | ||
|