mark cerqueira well-rounded nerd

Android Emails with Multiple File Attachments

The other day I was looking to create a share intent in Android with multiple file attachments. As always, especially with anything related to security and permissions, there were many “solutions” to be found but none that worked.

After some engineering – many trials and many errors – here’s the final output that did the trick:

The trick is to use FileProvider to create content URIs via FileProvider.getUriForFile from within your app. These URIs can be used by the receiving app. You’ll need to create a provider in your manifest file…

… and define paths in a paths file. Note that since I was creating my files in the cache directory my file path file specifies cache-path.

Happy coding!