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"