I am not able to attach an excel file from assets folder using email intent in android. Can anyone please suggest what is wrong in the below code. The email opens but a message
First, assets/test.xlsx
is not a file on the Android device. It is an asset, packaged in your APK. Hence, new File("assets/test.xlsx")
.
Second, even if there was a file at that path, third-party email apps cannot read it.
Either:
Copy the file to external storage, then create a Uri
to that and use it in your Intent
, or
Copy the file to internal storage and use FileProvider to serve it, or
Use my StreamProvider to serve it straight from assets