我正在尝试以编程方式将图像附加到我的应用程序中的电子邮件正文。我已经看到了一些关于如何执行该操作的主题并将我的代码完全相同的方式但是它无用我没有得到图像另一方(来自post)。 有关更多信息,请访问我的代码:
Intent emailIntent=new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("image/jpg");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.mail_partage_objet));
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(readEmailTemplate()));
String imageFilePath=Constants.PHOTO_CACHE_PATH+"/"+currentPlace.getPhotoFileName();
Log.d(TAG,"Picture Path: "+imageFilePath);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageFilePath));
startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.email_share)));
其中PHOTO_CACHE_PATH是保存图像的目录路径,它位于SD卡上
答案 0 :(得分:0)
我想你忘记了:emailIntent.setType("application/octet-stream");
。
多附件的示例:
Intent exportMessageIntent = new Intent(
android.content.Intent.ACTION_SEND_MULTIPLE);
exportMessageIntent.setType("text/plain");
exportMessageIntent.setType("application/octet-stream");
ArrayList<Uri> uris = new ArrayList<Uri>();
//array of urls to your files on device - they are strings
filePaths = new String[] { "path1","path2" }; //for your case just insert imageFilePath -> filePaths = new String[] { imageFilePath };
//create files from string array of paths
for (String file : filePaths) {
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
exportMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
uris);
exportMessageIntent
.putExtra(Intent.ACTION_DEFAULT, "test/");
exportMessageIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject text");
exportMessageIntent.putExtra(Intent.EXTRA_TEXT,"bodytext");
startActivity(exportMessageIntent);
希望它有所帮助, 托尼