如何使用电子邮件附件发送音频和图像文件?

时间:2014-01-17 12:54:24

标签: android email android-intent email-integration

我正在尝试发送附有声音文件和图像文件附件的电子邮件。我可以附加这两个文件,但是当我尝试发送它时,我会收到弹出消息“很遗憾Gmail已经停止了”。

代码在这里: -

    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("Audio/mp3");
intent.setType("image/png");

intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app");
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file ");

intent.putExtra(Intent.EXTRA_EMAIL,
        new String[] { "xxx@gmail.com" });
ArrayList<Uri> uris = new ArrayList<Uri>();

uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath())));
uris.add(Uri.parse(picturePath.toString()));
//intent .putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath.toString()));


intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

// startActivity(Intent.createChooser(intent, "Send mail"));
startActivityForResult(Intent.createChooser(intent, "Send mail"),
        EMAIL_REQUEST);

4 个答案:

答案 0 :(得分:1)

在谷歌和RND之后我解决了这个问题。请遵循此代码。

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("Audio/mp3");
    intent.setType("image/jpg");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app");
    intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file ");
            intent.putExtra(Intent.EXTRA_EMAIL,
            new String[] { "xxx@gmail.com" });
    ArrayList<Uri> uris = new ArrayList<Uri>();
            String[] filePaths = new String[]{mFileName.getAbsolutePath(),picturePath.toString()};
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            startActivityForResult(Intent.createChooser(intent, "Send mail"),
            EMAIL_REQUEST );
    startActivityForResult(Intent.createChooser(intent, "Send mail"),
            RESULT_LOAD_IMAGE );

答案 1 :(得分:0)

发送试试此代码

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test");
//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(emailIntent);

答案 2 :(得分:0)

对于mp3文件,

intent.setType("audio/mpeg"),看看MIME类型!

答案 3 :(得分:0)

使用settype是*。

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("*/*");


intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app");
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file ");

intent.putExtra(Intent.EXTRA_EMAIL,
        new String[] { "xxx@gmail.com" });
ArrayList<Uri> uris = new ArrayList<Uri>();

uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath())));
uris.add(Uri.parse(picturePath.toString()));
//intent .putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath.toString()));


intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

// startActivity(Intent.createChooser(intent, "Send mail"));
startActivityForResult(Intent.createChooser(intent, "Send mail"),
        EMAIL_REQUEST);