【问题标题】:How to attach pdf file in an email [closed]如何在电子邮件中附加pdf文件[关闭]
【发布时间】:2013-11-20 07:57:25
【问题描述】:

我想在电子邮件中附加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 :"));

【问题讨论】:

    标签: android email pdf


    【解决方案1】:

    试试这个:

    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);
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      四处搜索后,我发现这是显示如何将文件存储到外部存储器

      Developers Link

      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);
      

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

      【讨论】:

      • 请接受这个作为答案。如果它正在工作。非常感谢。
      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 2014-07-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 2020-11-21
      • 1970-01-01
      相关资源
      最近更新 更多