0

我必须解决以下问题:

我想发送一封附有图片的电子邮件。我写了这段代码:

    File file = context.getDir("Files", context.MODE_WORLD_WRITEABLE);
    File image = new File(file, "image.jpg");

    Uri U = Uri.fromFile(image);
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("image/jpg");
    i.putExtra(Intent.EXTRA_STREAM, U);
    context.startActivity(Intent.createChooser(i, "Email:"));

电子邮件已发送,但没有附件。

有人知道为什么发送的电子邮件没有附件吗?

编辑

我找到了我的问题的答案。由于图像存储在内部存储中,它没有足够的权限,因此无法通过电子邮件发送。我已将图像移至 externalStorage,现在它可以工作了:)

谢谢,方舟

4

2 回答 2

1

试试这个——

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);

也可以看看我的现有答案

于 2012-06-11T15:07:33.197 回答
1
String smsBody = "Body of the Content";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject of the Mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, smsBody);
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile("mnt/sdCard/SampleImageFloder/TestImage.png"));
emailIntent.setType("vnd.android.cursor.dir/email");
activity.startActivity(Intent.createChooser(emailIntent,"Email:"));
于 2012-06-11T15:10:25.870 回答