Android系统。发送多附件电子邮件

时间:2010-05-17 08:23:29

标签: android email attachment

我想通过

发送电子邮件
startActivity(Intent.createChooser(new Intent(android.content.Intent.ACTION_SEND)))

我知道要将文件附加到我需要的电子邮件

intentEmail.putExtra(android.content.Intent.EXTRA_STREAM, <Uri of file>)

但我需要附上几个文件。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

这应该可以发送多个附件

public static void sendEmail(Context context, String emailTo, String emailCC,
            String subject, String message, List<String> filePaths)
        {
            //send email with multiple attachments
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
                new String[]{emailTo});
            emailIntent.putExtra(android.content.Intent.EXTRA_CC, 
                new String[]{emailCC});
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
                    subject);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
                    message);
            ArrayList<Uri> uris = new ArrayList<Uri>();
            //convert from paths to Uri's
            for (String file : filePaths)
            {
                File fileIn = new File(file);
                Uri u = Uri.fromFile(fileIn);
                uris.add(u);
         }

            emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            context.startActivity(emailIntent);
        }