react-native-mail icon indicating copy to clipboard operation
react-native-mail copied to clipboard

Android: Support for URI and attaching files from internal storage (SOLVED)

Open ujwal-setlur opened this issue 8 years ago • 5 comments

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);
      }

I have made these changes in my fork of this repo, and I have also incorporated the pull request https://github.com/chirag04/react-native-mail/pull/42 by rusel1989

However, I can't make a pull request because I am using react-native 0.39, and the latest repo is for react-native 0.40.

If anyone needs this functionality, they are welcome to look at my fork

https://github.com/ujwal-setlur/react-native-mail

-ujwal

ujwal-setlur avatar Jan 21 '17 22:01 ujwal-setlur

Thanks man, that was exactly what I needed

pallendes avatar Jan 31 '17 20:01 pallendes

I have issued pull request https://github.com/chirag04/react-native-mail/pull/71

ujwal-setlur avatar Aug 07 '17 23:08 ujwal-setlur

Was this ever merged?

cristianoccazinsp avatar Apr 26 '19 17:04 cristianoccazinsp

Nope

ujwal-setlur avatar Apr 26 '19 17:04 ujwal-setlur

Such a Tiny fix, @chirag04 can you please implement this. Is this even still maintained?

cristianoccazinsp avatar Apr 26 '19 17:04 cristianoccazinsp