Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added URI support #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ujwal-setlur
Copy link

Currently, emails cannot be attached on android unless the attachment is on an external storage. This can be resolved by:

  1. Using a FileProvider such as a react-native-file-provider so that internal files are exposed as contentUri

  2. Code changes in RNMailModule.java to check if the path is a URI or a file path

      import android.webkit.URLUtil;

      if (attachment.hasKey("path") && !attachment.isNull("path")) {
        String path = attachment.getString("path");
        Uri p;
        // Check for valid URI
        if (URLUtil.isValidUrl(path)) {
          p = Uri.parse(path);
        }
        // Else this is an absolute file path
        else {
          File file = new File(path);
          p = Uri.fromFile(file);
        }
        i.putExtra(Intent.EXTRA_STREAM, p);
      }

@sakarit-zz
Copy link

Please merge

@ghost
Copy link

ghost commented Oct 9, 2017

is this working?

@sakarit-zz
Copy link

Well... the code above works, but I couldn't get the attachments to Gmail app. I tried using react-native-file-provider and added the provider settings to AndroidManifest.xml, but it just doesn't work (spent a whole day trying to get it to work). It seems that Gmail app only accepts attachments from the external storage area..

I gave up and tried react-native-mail-compose. It works for Android, but the file has to be read as base64 string so I'm using react-native-fetch-blob for it (I already had it in my project).

@ghost
Copy link

ghost commented Oct 9, 2017

i need to attach pdf's into the gmail app, so you recommend to use react-native-mail-compose?

@sakarit-zz
Copy link

Yes! Use it with react-native-fetch-blob so you can read the files as base64 encoded strings out of the box.

https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readfilepath-encodingpromise

@ghost
Copy link

ghost commented Oct 9, 2017

thx so much :D

@ujwal-setlur
Copy link
Author

It worked for me with Gmail

@ThomasStubbe
Copy link

Please merge this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants