In an app I have, users submit files to a specified email address a lot. It seems 95%+ have no problem, but this is a particular issue that seems to affect some users, and only sometimes. But frequently enough to be annoying.
Their email sends, but there is no attachment. They will try 2,3,4 times and eventually it will send with the attachment. From one user, I have learned they use Gmail and DO see the attachment prior to pressing "send".
The users' Android API levels vary from 19 to 29 and everything in between.
Here is the code for composing the email intent:
public int emailSubmission(File fileToSend)
{
Uri uri = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", fileToSend);
else
uri = Uri.fromFile(fileToSend);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/message");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"email@email.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Hello world!");
intent.putExtra(Intent.EXTRA_STREAM, uri);
try
{
startActivity(Intent.createChooser(intent, "Email submission..."));
}
catch (ActivityNotFoundException e)
{
logNonFatalException(e);
return 2;
}
return 1;
}
It seems pretty standard, but I can't figure out what is causing this problem? I also do not know if it is specific to Gmail. Is there anything else I can even try to get rid of this intermittent issue? All "email intent" Android code I see online looks just like this, specifically for attachments and EXTRA_STREAM and the URI code.