not able to attach excel file from assets folder

前端 未结 1 421
[愿得一人]
[愿得一人] 2021-01-27 01:58

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

相关标签:
1条回答
  • 2021-01-27 02:28

    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

    0 讨论(0)
提交回复
热议问题