Intent.ACTION_SEND不发送附件

时间:2015-01-16 15:14:25

标签: android email android-intent attachment

当我按下按钮时,我的应用会发送电子邮件。我需要附加一个.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文件)。但是当我发送电子邮件时,接收者没有任何附件。

1 个答案:

答案 0 :(得分:1)

Environment.getExternalStorageState()静态方法返回主要“外部”存储的状态,如MEDIA_UNKNOWN, MEDIA_REMOVED, MEDIA_UNMOUNTED而不是存储路径。

删除您在文件路径之前添加的getExternalStorageState

File file = new File("/storage/sdcard0/myfile.csv");

如果文件存储在设备的主存储中,则使用Environment.getExternalStorageDirectory获取存储目录,而不是使用静态。

相关问题