【问题标题】:Attachment Issue in Intent意图中的附件问题
【发布时间】:2012-05-08 07:53:43
【问题描述】:

我一直在开发 Android 程序,使用 IntentIntent.ACTION_SEND 发送带有附件(文本/纯文本)的电子邮件我使用 Intent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uri) 但是,当我尝试将多个文件附加到同一封邮件时多次调用Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri),它失败了。电子邮件中未显示任何附件。在此先感谢

      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
      System.out.println(emailText+emailTo);
      emailIntent.setType("text/plain");
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailText);
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailTo});

      //has to be an ArrayList
      ArrayList<Uri> uris = new ArrayList<Uri>();

      //convert from paths to Android friendly Parcelable Uri's
      try
      {
            for (String file : filePaths)
            {
                File fileIn = new File(context.getFilesDir(),file);
                System.out.println(fileIn+"yes");
                Uri u =  Uri.fromFile(fileIn);
                uris.add(u);
                System.out.println(u);
            }
      emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);
      context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
      }

【问题讨论】:

  • 试试我以前的answer 这个问题。
  • 你的答案和我的问题一样
  • 您是否要在其中附加多个文件?
  • 是的,正如我在上面的问题中提到的那样。
  • 当我使用此代码时,会显示附件,但发送邮件后我没有收到任何附件。

标签: android android-intent email-attachments


【解决方案1】:

使用 ACTION_SEND_MUTIPLE 代替 ACTION_SEND

http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND_MULTIPLE

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);

【讨论】:

  • 谢谢,我做到了,但遇到了同样的问题,我在一个问题上浪费了我 2 天的时间。如果你能,请帮忙
  • 您使用哪个电子邮件应用程序?使用标准“电子邮件”应用程序“文件太大而无法附加”时出现错误。但是我在使用 Gmail 时没有收到警告。尝试使用其他邮件应用程序,看看是否有所作为。
  • 我同时使用 Gmail 和 yahoo,但我在这两个应用程序中都没有收到任何附件,我不知道我哪里做错了。
  • 在模拟器中运行是否得到同样的结果?
【解决方案2】:

确保第二个参数file 只提供一个有效的文件名。你的问题可能就在那里......

File fileIn = new File(context.getFilesDir(),file);

以下代码可以正常工作..

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
//...
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath() + "/HOME/Pictures/1.png"));
uris.add(Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath() + "/HOME/Pictures/2.png"));
uris.add(Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath() + "/HOME/Pictures/3.png"));
uris.add(Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath() + "/HOME/Pictures/4.png"));
emailIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 2021-06-09
    • 2011-08-23
    • 1970-01-01
    • 2010-11-14
    相关资源
    最近更新 更多