Skip to content

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

Open
@ujwal-setlur

Description

@ujwal-setlur

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
#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions