【发布时间】:2015-01-16 15:14:25
【问题描述】:
当我按下按钮时,我的应用程序会发送一封电子邮件。我需要附加一个 .csv 文件。代码如下:
Intent email = new Intent(Intent.ACTION_SEND);
File file = new File(Environment.getExternalStorageState()+"/storage/sdcard0/myfile.csv");
Uri path = Uri.fromFile(file);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"aaa@xxx.it"});
email.putExtra(Intent.EXTRA_SUBJECT, "Some text");
email.putExtra(Intent.EXTRA_TEXT, "Some text");
email.putExtra(Intent.EXTRA_STREAM, path);
email.setType("application/octet-stream");
startActivityForResult(Intent.createChooser(email, "Select client"),1222);
当我运行应用程序并按下发送按钮时,会出现一个弹出窗口,我选择客户端电子邮件。 打开客户端后,我可以阅读文本、主题、电子邮件,并且可以在底部看到附件(.csv 文件)。但是当我发送电子邮件时,收件人没有任何附件。
【问题讨论】:
-
你希望
Environment.getExternalStorageState()做什么? -
网上冲浪我发现出于某些安全原因,您不能直接将文件附加到电子邮件中
标签: android email android-intent attachment