如何在电子邮件中附加pdf文件

man*_*ani 4 pdf email android

我想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 :"));
Run Code Online (Sandbox Code Playgroud)

Sid*_*yas 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);
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.


小智 6

搜索后我发现这是为了说明如何将文件存储到外部存储器

开发者链接

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);
Run Code Online (Sandbox Code Playgroud)

上面的链接显示了如何删除文件,并说明如何将它们放在正确的文件夹中,以避免覆盖其他文件.希望这可以帮助其他人解决同样的问题