【问题标题】:Intent.ACTION_SEND doesn't send attachmentIntent.ACTION_SEND 不发送附件
【发布时间】: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 文件)。但是当我发送电子邮件时,收件人没有任何附件。

【问题讨论】:

标签: android email android-intent attachment


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2011-06-20
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 2019-07-02
    • 2012-09-01
    相关资源
    最近更新 更多