Skip to content
Open

Fixes #140

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions android/src/main/java/com/chirag/RNMail/RNMailModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.StrictMode;
import android.text.Html;

import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -26,6 +27,8 @@ public class RNMailModule extends ReactContextBaseJavaModule {
public RNMailModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}

@Override
Expand Down Expand Up @@ -53,8 +56,14 @@ private String[] readableArrayToStringArray(ReadableArray r) {

@ReactMethod
public void mail(ReadableMap options, Callback callback) {
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:"));
Intent i;
if (options.hasKey("attachment") && !options.isNull("attachment")) {
i = new Intent(Intent.ACTION_SEND);
i.setType("vnd.android.cursor.dir/email");
} else {
i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:"));
}

if (options.hasKey("subject") && !options.isNull("subject")) {
i.putExtra(Intent.EXTRA_SUBJECT, options.getString("subject"));
Expand All @@ -63,7 +72,7 @@ public void mail(ReadableMap options, Callback callback) {
if (options.hasKey("body") && !options.isNull("body")) {
String body = options.getString("body");
if (options.hasKey("isHTML") && options.getBoolean("isHTML")) {
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body).toString());
} else {
i.putExtra(Intent.EXTRA_TEXT, body);
}
Expand Down