From 14489d5eb4e0d1d10c376a788323639fd5cdfa2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Marty=C4=8D=C3=A1k?= Date: Mon, 31 Oct 2016 10:11:22 +0100 Subject: [PATCH 1/2] [android] Let user specify custom chooser label --- README.md | 3 ++- android/src/main/java/com/chirag/RNMail/RNMailModule.java | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c118f8e..04cc7ad 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,8 @@ var MailExampleApp = React.createClass({ path: '', // The absolute path of the file from which to read data. type: '', // Mime Type: jpg, png, doc, ppt, html, pdf name: '', // Optional: Custom filename for attachment - } + }, + chooserLabel: '' // Android only, the label displayed on chooser }, (error, event) => { if(error) { AlertIOS.alert('Error', 'Could not send mail. Please send a mail to support@example.com'); diff --git a/android/src/main/java/com/chirag/RNMail/RNMailModule.java b/android/src/main/java/com/chirag/RNMail/RNMailModule.java index af50d0c..fc52b39 100644 --- a/android/src/main/java/com/chirag/RNMail/RNMailModule.java +++ b/android/src/main/java/com/chirag/RNMail/RNMailModule.java @@ -104,7 +104,13 @@ public void mail(ReadableMap options, Callback callback) { callback.invoke("error"); } } else { - Intent chooser = Intent.createChooser(i, "Send Mail"); + String chooserLabel; + if (options.hasKey("chooserLabel") && !options.isNull("chooserLabel")) { + chooserLabel = options.getString("chooserLabel"); + } else { + chooserLabel = "Send Mail"; + } + Intent chooser = Intent.createChooser(i, chooserLabel); chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { From 38a430db0b9ee50b7bb4a77c71f1a98f2286d650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Marty=C4=8D=C3=A1k?= Date: Mon, 31 Oct 2016 09:40:47 +0100 Subject: [PATCH 2/2] [android] Use ACTION_SEND where attachment is present --- README.md | 3 ++- .../src/main/java/com/chirag/RNMail/RNMailModule.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04cc7ad..9934334 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,8 @@ var MailExampleApp = React.createClass({ ``` ### Note -On android callback will only have error(if any) as the argument. event is not available on android. +- If you use attachment on android, file must be located in external storage directory or world readable (unsafe). +- On android callback will only have error(if any) as the argument. event is not available on android. ## Here is how it looks: ![Demo gif](https://github.com/chirag04/react-native-mail/blob/master/screenshot.jpg) diff --git a/android/src/main/java/com/chirag/RNMail/RNMailModule.java b/android/src/main/java/com/chirag/RNMail/RNMailModule.java index fc52b39..b27fcfd 100644 --- a/android/src/main/java/com/chirag/RNMail/RNMailModule.java +++ b/android/src/main/java/com/chirag/RNMail/RNMailModule.java @@ -52,8 +52,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"));