我将在邮件中附加“.csv”并发送。但面临 csv 文件在接收方不可用的问题。
我尝试了太多 Mime 类型
application/octet-stream, text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel
但该文件未随邮件附上。
下面是我用来发送邮件的代码
public boolean sendEmail() {
boolean success = false;
Intent intentSendMail = new Intent(Intent.ACTION_SEND);
File mydir = getApplicationContext().getDir(Global.FOLDERNAME, Context.MODE_PRIVATE);
File fileWithinMyDir = new File(mydir, Global.FILENAME);
if (!fileWithinMyDir.exists() || !fileWithinMyDir.canRead()) {
Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
success = false;
} else {
intentSendMail.setType("text/csv");
intentSendMail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileWithinMyDir));
intentSendMail.putExtra(Intent.EXTRA_SUBJECT,
"Subject");
intentSendMail.putExtra(Intent.EXTRA_TEXT, "Sent from my phone.");
startActivity(Intent.createChooser(intentSendMail, "E-mail"));
success = true;
}
return success;
}
提前致谢..