我想从资产文件夹附加多个图像。电子邮件发送成功但没有附加图像。在电子邮件中显示图像0 kb。 我的代码在这里。请提出任何想法。其他任何方式发送多个图像。
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("jpeg/image");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0; i < arrImageslist.size(); i++)
{
Uri u=Uri.parse("file:///android_asset/DiseaseImages/"+arrImageslist.get(i));
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris);
startActivity(android.content.Intent.createChooser(emailIntent, "Send mail..."));
答案 0 :(得分:1)
第一部分......
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("plain/text");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"abc@gmail.com"});
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Accident Capture");
sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
ArrayList<Uri> uriList = getUriListForImages();
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
Log.d(TAG, "Size of the ArrayList :: " +uriList.size());
FormHolderActivity.this.startActivity(Intent.createChooser(sendIntent, "Email:"));
------------------ GetUriListForImages ---------------------------- ----
private ArrayList<Uri> getUriListForImages() throws Exception {
ArrayList<Uri> myList = new ArrayList<Uri>();
String imageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/folder/";
File imageDirectory = new File(imageDirectoryPath);
String[] fileList = imageDirectory.list();
if(fileList.length != 0) {
for(int i=0; i<fileList.length; i++)
{
try
{
ContentValues values = new ContentValues(7);
values.put(Images.Media.TITLE, fileList[i]);
values.put(Images.Media.DISPLAY_NAME, fileList[i]);
values.put(Images.Media.DATE_TAKEN, new Date().getTime());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Images.ImageColumns.BUCKET_ID, imageDirectoryPath.hashCode());
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileList[i]);
values.put("_data", imageDirectoryPath + fileList[i]);
ContentResolver contentResolver = getApplicationContext().getContentResolver();
Uri uri = contentResolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
myList.add(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return myList;
}