I need to send a file through email from my application (sqlite file with custom extension .qmd). The file is stored within my app data and I use content provider to expose it and provide Uri to the email intent. Android email client on Huawei g750 device opens the composed message with correct TO, Subject, and Body and displays a toast saying "your file cannot be attached to your email".
I've been around the web for a while (almost 5 hours) for this, tried every possible combination of content-type & extras, I'm having an interesting behavior:
- file is being attached successfully on Android email client on HTC One.
- file is being attached successfully on Gmail app. on both devices (HTC & Huawei)
- when I change the file extension to one of the common extensions (i.e. .txt, .zip, .xml, .mdb, ... and many others) it is attached successfully.
- when I click attach from within the compose screen and select the file from file manager it is attached successfully.
Here is the code I use (I tried too many combinations but this is the simplest and it is doing the same thing), hopefully someone have an idea about what's going on.
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject text");
emailIntent.putExtra(Intent.EXTRA_TEXT, "body text");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(FileProvider.CONTENT_URI + new File(file).getName()));
startActivity(Intent.createChooser(emailIntent, "Send by email ..."));