Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions ExampleApp/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android_</name>
<comment>Project android_ created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions ExampleApp/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactlibrary.mailcompose">

<application android:label="@string/app_name">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">react-native-mail-compose</string>
</resources>
9 changes: 9 additions & 0 deletions android/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_files"
path="." />
<files-path
name="files-path"
path="." /> <!-- Used to access into application data files -->
</paths>
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -24,6 +24,9 @@
"android"
],
"author": "Joon Ho Cho <[email protected]>",
"contributors":[
"Willy Martin <[email protected]> (https://github.com/nowarzz)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/joonhocho/react-native-mail-compose/issues"
Expand Down