我从PHP服务器获取一个图像作为字符串(this image),我希望通过电子邮件将此图像作为附件发送。
当我尝试发送电子邮件时,附件是纸张,但接收器端只显示纯文本。如何正确发送电子邮件?
这是我的代码:
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
String img_source = listBuzzInfoBean.get(photo).getBuzzImage();
File downloadedPic = new File(Environment.getExternalStorageDirectory(), img_source + ".jpg");// Art_Nature
Log.d("++++++++++++++", img_source);
Uri myUri = Uri.fromFile(downloadedPic);
picMessageIntent.putExtra(Intent.EXTRA_STREAM, myUri); //screenshotUri
startActivity(Intent.createChooser(picMessageIntent, "Share image using"));
答案 0 :(得分:0)
我使用以下代码来处理这个问题。我注意到Gmail / Mail应用程序之间的差异以及它们如何处理此意图。
这篇文章似乎也有类似的问题。 Android: Intent.ACTION_SEND with EXTRA_STREAM doesn't attach any image when choosing Gmail app on htc Hero
public static Intent createEmailWithAttachmentIntent(String[] addresses,
String[] ccAddresses, String subject, String contentType,
String filename, String messageBody) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Intent.EXTRA_EMAIL, addresses);
i.setType(contentType);
if(filename != null && !filename.equals(""))
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename)));
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, messageBody);
if (ccAddresses != null && ccAddresses.length > 0)
i.putExtra(Intent.EXTRA_CC, ccAddresses);
return i;
}