Gmail 5.0 app fails with “Permission denied for the attachment” when it receives ACTION_SEND intent

后端 未结 9 1171
感动是毒
感动是毒 2020-11-27 18:35

My app creates mails with attachments, and uses an intent with Intent.ACTION_SEND to launch a mail app.

It works with all the mail apps I tested with, e

相关标签:
9条回答
  • 2020-11-27 19:25

    Google have an answer for that issue:

    • Store the data in your own ContentProvider, making sure that other apps have the correct permission to access your provider. The preferred mechanism for providing access is to use per-URI permissions which are temporary and only grant access to the receiving application. An easy way to create a ContentProvider like this is to use the FileProvider helper class.

    • Use the system MediaStore. The MediaStore is primarily aimed at video, audio and image MIME types, however beginning with Android 3.0 (API level 11) it can also store non-media types (see MediaStore.Files for more info). Files can be inserted into the MediaStore using scanFile() after which a content:// style Uri suitable for sharing is passed to the provided onScanCompleted() callback. Note that once added to the system MediaStore the content is accessible to any app on the device.

    Also you can try set permissions for your file:

    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    

    And finally you can copy/store your files in external storage - permissions not needed there.

    0 讨论(0)
  • 2020-11-27 19:31

    I was able to pass a screenshot .jpeg file from my app to GMail 5.0 through an Intent. The key was in this answer.

    Everything I have from @natasky 's code is nearly identical but instead, I have the file's directory as

    context.getExternalCacheDir();
    

    Which "represents the external storage directory where you should save cache files" (documentation)

    0 讨论(0)
  • 2020-11-27 19:31

    Step 1: Add authority in your attached URI

    Uri uri = FileProvider.getUriForFile(context, ""com.yourpackage", file);

    Same as your manifest file provide name

    android:authorities="com.yourpackage"

    Step 2`; Add flag for allow to read

    myIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

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