我试图附加文本文件以便通过电子邮件发送,但是每当我打开电子邮件应用程序时,它都会说该文件不存在。
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(directory+"/data.txt"));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "An Error Happened ", Toast.LENGTH_SHORT).show();
}
如果您尝试通过电子邮件发送文件,请确保它们位于公共可访问位置,并告诉您它是您要发送的文件。使用此代码作为示例。
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822").putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}).putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail subject").putExtra(android.content.Intent.EXTRA_TEXT, "lalalala");
String targetFilePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "tmp" + File.separator + "test.txt";
Uri attachmentUri = Uri.parse(targetFilePath);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + attachmentUri));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句