保存文件,然后通过邮件发送

问题描述 投票:0回答:1

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

i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
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));

你能帮助我吗?

来自德国沃尔夫冈的问候

android save attachment send
1个回答
0
投票

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

        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..."));
© www.soinside.com 2019 - 2024. All rights reserved.