使用Android的意图多个电子邮件附件 [英] Android multiple email attachments using Intent

查看:226
本文介绍了使用Android的意图多个电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对Android程序与使用意图与 ACTION_SEND 附件(图像文件,音频文件等)发送电子邮件。该方案是工作时的电子邮件有一个附件。我用 Intent.putExtra(android.content.Intent.EXTRA_STREAM,URI)到指定的图像文件附加到邮件,它工作正常,该邮件可以通过交付在Gmail中。但是,当我试图通过调用具有连接到同一个邮件多张图片 Intent.putExtra(android.content.Intent.EXTRA_STREAM,URI)多次,但未能奏效。没有一个附件显示在电子邮件。

I've been working on Android program to send email with an attachment (image file, audio file, etc) using Intent with ACTION_SEND. The program is working when email has a single attachment. I used Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri) to attach the designated image file to the mail and it is working fine, the mail can be delivered through the Gmail. However, when I tried to have multiple images attached to the same mail by calling Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri) multiple times, it failed to work. None of the attachment show up in the email.

我搜索了SDK文档和Android编程的用户群有关电子邮件的附件,但找不到任何相关信息。然而,我发现,还有另外一个意图不变 ACTION_SEND_MULTIPLE (自API等级4),这可能会满足我的要求。基于SDK文档,它只是说,它提供多种数据​​给别人,它就像 ACTION_SEND ,不同的是数据多。但我仍然无法找出正确使用此命令。我试着用 ACTION_SEND_MULTIPLE 声明的意图,然后调用 putExtra(EXTRA_STREAM,URI)多次附上多张图片,但我得到了同样的错误的结果像以前一样,没有任何附件出现在电子邮件。

I searched the SDK documentation and Android programming user group about email attachment but cannot find any related info. However, I've discovered that there's another intent constant ACTION_SEND_MULTIPLE (available since API level 4) which might meet my requirement. Based on SDK documentation, it simply states that it deliver multiple data to someone else, it works like ACTION_SEND, except the data is multiple. But I still could not figure out the correct usage for this command. I tried to declare intent with ACTION_SEND_MULTIPLE, then call putExtra(EXTRA_STREAM, uri) multiple times to attach multiple images, but I got the same erroneous result just like before, none of the attachment show up in the email.

有没有人试图与 ACTION_SEND_MULTIPLE ,并把它与多个电子邮件附件的工作?

Has anyone tried with ACTION_SEND_MULTIPLE and got it working with multiple email attachment?

推荐答案

下面是你需要创建一个包含多个附件的emailIntent的code。

Here is the code you need to create an emailIntent that contains multiple attachments.

public static void email(Context context, String emailTo, String emailCC,
    String subject, String emailText, List<String> filePaths)
{
    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    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(Intent.EXTRA_SUBJECT, subject); 
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<Uri>();
    //convert from paths to Android friendly Parcelable 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(Intent.createChooser(emailIntent, "Send mail..."));
}

这篇关于使用Android的意图多个电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆