diff --git a/ExampleApp/android/.project b/ExampleApp/android/.project new file mode 100644 index 0000000..0e0a1ba --- /dev/null +++ b/ExampleApp/android/.project @@ -0,0 +1,17 @@ + + + android_ + Project android_ created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/ExampleApp/android/.settings/org.eclipse.buildship.core.prefs b/ExampleApp/android/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..e889521 --- /dev/null +++ b/ExampleApp/android/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir= +eclipse.preferences.version=1 diff --git a/README.md b/README.md index ee5a0c6..a4ca1ad 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,8 @@ async sendMail() { ext: '.txt', mimeType: 'text/plain', text: 'Hello my friend', // Use this if the data is in UTF8 text. - data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text. + data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text., + url:'path to the file' // Use this if the data is path to the attachment file }], }); } catch (e) { diff --git a/android/.project b/android/.project new file mode 100644 index 0000000..3964dd3 --- /dev/null +++ b/android/.project @@ -0,0 +1,17 @@ + + + android + Project android created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..e889521 --- /dev/null +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir= +eclipse.preferences.version=1 diff --git a/android/build.gradle b/android/build.gradle index 69ac46b..2fe51df 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion 28 + buildToolsVersion "28.0.1" defaultConfig { minSdkVersion 16 - targetSdkVersion 22 + targetSdkVersion 28 versionCode 1 versionName "1.0" ndk { diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 9758ec9..573bfc1 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,14 @@ - + + + + + diff --git a/android/src/main/java/com/reactlibrary/mailcompose/RNMailComposeModule.java b/android/src/main/java/com/reactlibrary/mailcompose/RNMailComposeModule.java index f0f2bd0..23ac4de 100644 --- a/android/src/main/java/com/reactlibrary/mailcompose/RNMailComposeModule.java +++ b/android/src/main/java/com/reactlibrary/mailcompose/RNMailComposeModule.java @@ -8,6 +8,7 @@ import android.text.Html; import android.text.Spanned; import android.util.Base64; +import android.support.v4.content.FileProvider; import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.BaseActivityEventListener; @@ -35,7 +36,10 @@ public class RNMailComposeModule extends ReactContextBaseJavaModule { - private static final int ACTIVITY_SEND = 129382; + + //Updating to RN 0.59.* + //Fixing issue: can only use lower 16 bits for requestCode on Intent + private static final int ACTIVITY_SEND = 65510; private Promise mPromise; @@ -45,11 +49,10 @@ public class RNMailComposeModule extends ReactContextBaseJavaModule { public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) { if (requestCode == ACTIVITY_SEND) { if (mPromise != null) { - if (resultCode == Activity.RESULT_CANCELED) { - mPromise.reject("cancelled", "Operation has been cancelled"); - } else { - mPromise.resolve("sent"); - } + //no matter what is the action on the email apps, the resultCode will reply for 0 or equals to RESULT_CANCEL + //refer to: https://stackoverflow.com/questions/3778048/how-can-we-use-startactivityforresult-for-email-intent + //always treat it as sent after user redirected to the mailing apps + mPromise.resolve("sent"); mPromise = null; } } @@ -107,6 +110,7 @@ private void addAttachments(Intent intent, ReadableArray attachments) { if (attachment != null) { byte[] blob = getBlob(attachment, "data"); String text = getString(attachment, "text"); + String url = getString(attachment,"url"); // String mimeType = getString(attachment, "mimeType"); String filename = getString(attachment, "filename"); if (filename == null) { @@ -120,10 +124,13 @@ private void addAttachments(Intent intent, ReadableArray attachments) { tempFile = writeBlob(tempFile, blob); } else if (text != null) { tempFile = writeText(tempFile, text); + } else if(url != null){ + tempFile = new File(url); } if (tempFile != null) { - uris.add(Uri.fromFile(tempFile)); + Uri tempFileUri = FileProvider.getUriForFile(getCurrentActivity(),this.getReactApplicationContext().getPackageName()+".provider",tempFile); + uris.add(tempFileUri); } } } diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml new file mode 100644 index 0000000..485f5d2 --- /dev/null +++ b/android/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + react-native-mail-compose + diff --git a/android/src/main/res/xml/provider_paths.xml b/android/src/main/res/xml/provider_paths.xml new file mode 100644 index 0000000..1434ff0 --- /dev/null +++ b/android/src/main/res/xml/provider_paths.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/package.json b/package.json index f9f8ba7..a814afe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-mail-compose", - "version": "0.0.6", + "version": "0.0.9", "description": "React Native library for composing email. Wraps MFMailComposeViewController for iOS and Intent for Android.", "main": "index.js", "scripts": { @@ -24,6 +24,9 @@ "android" ], "author": "Joon Ho Cho ", + "contributors":[ + "Willy Martin (https://github.com/nowarzz)" + ], "license": "MIT", "bugs": { "url": "https://github.com/joonhocho/react-native-mail-compose/issues"