Android Attaching a file to GMAIL - Can't attach empty file

房东的猫 提交于 2019-11-29 03:05:43
GuiFGDeo

Ok, got it to work now, after a lot of research and intercepting some Intents.

What I had to do was change the file:/// to content://.

I did this following this information from Android: https://developer.android.com/reference/android/support/v4/content/FileProvider.html

The only major change was that I used a hard-coded path to /sdcard/file.ext. Also, the line

getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);

was changed to

Uri contentUri = FileProvider.getUriForFile(this, "com.mydomain.fileprovider", newFile);

Also had to include:

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
i.setData(contentUri);

I do not really understand why I had to change from File to Content, but after this, the file is now being attached again! See the link if you face this issue, and don't forget about the new .xml that needs to be created.

mkabatek

See the following question:

android-6-cannot-share-files-anymore

This behavior is with Android 6.0 and Gmail. Please see the following thread.

Issue 3141 - android-developer-preview

If you go to Settings->Apps->Gmail->Permissions and enable the "Storage" permission manually, then the share works.

Gmail should ask for "Storage" permission in this scenario and it would work as it did in all the past version of Android.

Other email apps should handle attachments correctly.

Here is how to fix it.

Go to Settings -> Apps -> Gmail -> Permissions Turn on the permission for "Storage" That work-around solved the issue for me.

I couldn't find a clear answer(sending an attachment on gmail without SD card) I tried to copy to another file name but no cigar. The way I got it to work was copy to the Downloads folder and go from there.

Get the path for Downloads with this Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

pulls the full path to downlaods folder copy the attachemnt to there and we are good. Files over 20M don't go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!