Quantcast
Channel: User HaimS - Stack Overflow
Viewing all articles
Browse latest Browse all 19

Answer by HaimS for Unable to programmatically attach file to an email intent using a FileProvider

$
0
0

Looks like gmail can't find the file you are trying to attach.It says: "FileNotFoundException when openAssetFileDescriptor"

Make sure the file created here has a valid path to an existing file.

File attachFile = new File(aDirectory, aFileName);

Further notes:

  • FileProvider.getUriForFile() is the way to go these days.That is, your alternative approaches won't work.
  • When passing a File object to FileProvider.getUriForFile() make sure the underline path of that file doesn't contain any uri prefix such as "://file" or "://content". It should be a simple path representation. For example: "/storage/emulated/0/myapp/myfile.jpg". In particular, don't use URL encoding in your path. For example, if you have a space in your path do: "/storage/emulated/0/myapp/my attachments/myfile.jpg" rather than "/storage/emulated/0/myapp/my%20attachments/myfile.jpg"

Viewing all articles
Browse latest Browse all 19

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>