我想在电子邮件中附加pdf
文件,我尝试使用此代码发送包含pdf
文件的电子邮件。
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
答案 0 :(得分:7)
试试这个:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("application/pdf");
shareIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc@gmail.com" });
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "test " + test);
shareIntent.putExtra(Intent.EXTRA_TEXT, "test");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///MyAPP/"+"test.pdf"));
startActivity(shareIntent);
希望这有帮助。
答案 1 :(得分:5)
搜索后,我发现这是为了展示如何将文件存储到外部存储器
createExternalStoragePublicPicture();
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "cards_01.pdf");
Intent intent = new Intent(Intent.ACTION_SEND ,Uri.parse("mailto:")); // it's not ACTION_SEND
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Card Set ");
intent.putExtra(Intent.EXTRA_TEXT, "");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
activity.startActivity(intent);
上面的链接显示了如何删除文件,并说明如何将它们放在正确的文件夹中以避免覆盖其他文件。希望这可以帮助其他任何有同样问题的人