guillaume-tgl
guillaume-tgl

Reputation: 2856

Empty attachment when exporting to Gmail

Users have recently started to report an issue when sharing files from my Android app using Gmail. The attachment is received empty by the recipient. I've never been able to reproduce on my devices but they've sent me such emails and I've seen the empty attachment.

This seems to happen exclusively on Android 7 and above.

Here is the way I share a file in my app:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName(activityInfo.packageName, activityInfo.name);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_TEXT, "Some text");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
Uri uri = FileProvider.getUriForFile(context, getFileProviderAuthority(), textFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
context.grantUriPermission(activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(intent);

For now, I haven't been able to understand why it happens for some users and not others. Most of them seem to have the latest version of Gmail.

One thing I noticed is that when I have a look at the original email I receive from these users, the ones from problematic users look like this:

----_com.android.email_1901922805148181 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: base64

*encoded email body*

----_com.android.email_1901922805148181  
Content-Type: text/plain;  name="filename.txt"  
Content-Transfer-Encoding: base64 
Content-Disposition: attachment;  filename="filename.txt";  size=262
----_com.android.email_1901922805148181--

And the ones from regular users look like this:

--001a1145af74a967fe0566ff756c 
Content-Type: text/html; charset="UTF-8" 
Content-Transfer-Encoding: quoted-printable

*email body*

--001a1145af74a967fe0566ff756c--
--001a1145af74a968010566ff756e 
Content-Type: text/plain; charset="US-ASCII"; name="log.txt" 
Content-Disposition: attachment; filename="log.txt" 
Content-Transfer-Encoding: base64 
Content-ID: <1620c22fd58144d0cc61> X-Attachment-Id: 1620c22fd58144d0cc61

*encoded attachment*

--001a1145af74a968010566ff756e--

Update

We've been able to reproduce this issue from any app that can share files via an ACTION_SEND intent, choosing Gmail and using an non-Google email account instead (ie not Gmail email address).

A necessary condition to reproduce is to add some text in the email body manually before sending the email (it's not enough to have some text in the intent EXTRA_TEXT). Without adding text, the attachment is sent correctly. With text, it cannot be opened by the receiver.

Upvotes: 4

Views: 461

Answers (1)

guillaume-tgl
guillaume-tgl

Reputation: 2856

It seems like this bug has been fixed in the latest version of Gmail for Android: 8.3.12.190852125

Upvotes: 2

Related Questions