【问题标题】:Save File and then send it by mail保存文件,然后通过邮件发送
【发布时间】:2019-02-14 01:32:11
【问题描述】:

我尝试保存一个文本文件,然后想通过邮件将其作为附件发送。 我可以保存文件,但是当我用“Extra_Stream”发送它时,手机说它无法发送文件。

i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"muellerswickrath@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Zeiterfassung");
StringBuilder sb = new StringBuilder();
sb.append(monteur.getText().toString() + " - Auftrag: " + auftrag.getText().toString() + "\n");

sb.append("*** Start *** \n");
for (int w = 0; w < x; w++) {
    sb.append(list.get(w).toString());
    sb.append("\n");
}
sb.append("*** Ende ***");
i.putExtra(Intent.EXTRA_TEXT, sb.toString());


String filename =  "muellers.xml";
String senden = "Testdatei";


FileOutputStream outputStream;

try {
    outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
    outputStream.write(senden.toString().getBytes());
    outputStream.close();
} catch (Exception e) {

    e.printStackTrace();
}

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filename));

你能帮帮我吗?

来自德国的问候 沃尔夫冈

【问题讨论】:

  • 也许可以试试 Uri.fromFile(fileName);

标签: android save attachment send


【解决方案1】:

这是我用来发送附件的意图:

        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
        emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
        context.startActivity(Intent.createChooser(emailIntent, "Send email..."));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 2014-10-18
    • 2011-07-24
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    相关资源
    最近更新 更多