1

我一直在使用我使用的 Android 程序来发送带有附件(文本/纯文本)的电子邮件Intent但是Intent.ACTION_SENDIntent.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..."));
      }
4

2 回答 2

2

使用 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);
于 2012-05-10T11:14:09.663 回答
0

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

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);
于 2014-03-22T10:15:00.620 回答