My application uses the intent method to send email to users as a convenient way to export Excel spreadsheet data (created by the JExcell API ).
The file is contained on the SD card in a folder named records .
The file I'm trying to send is a call to measurments.xls.
I tested the file presence in the code before sending. The email composer shows the attachment, but when I send and then receive the email, the attachment is not there.
However, if I substitute the excel file for the png image, the attachment will be received. So what gives?
Below is the code that I use to send emails, it is just a static method with class partitioning in my own way.
public static void sendEmailWithAttachment(Context ctx, String to,String subject, String message, String fileAndLocation)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {to});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
File file = new File(fileAndLocation);
if (file.exists())
{
Log.v("Farmgraze", "Email file_exists!" );
}
else
{
Log.v("Farmgraze", "Email file does not exist!" );
}
Log.v("FarmGraze", "SEND EMAIL FileUri=" + Uri.parse("file:/"+ fileAndLocation));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ fileAndLocation));
ctx.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
So what do I need to do to get the xls file? Change the mime types in the second line of the method code? If so, then what. Any helpful tips would be greatly appreciated.
Thanks for reading.
A.
source
share