After 1 day of work, finally, I can connect several image files from the \ sdcard \ accident \ folder for the mail client. To attach multiple files, I had to add images to the ContentResolver, which is responsible for the gallery image provider. Here is the full code ---
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); sendIntent.setType("plain/text"); sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {" soubhabpathak2010@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:"));
Thus, there are no changes in the first section of the code. But the change in the getUriListForImages () method is as follows:
private ArrayList<Uri> getUriListForImages() throws Exception { ArrayList<Uri> myList = new ArrayList<Uri>(); String imageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/accident/"; 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; }
This works great, and I can connect several image files to the default emulator email client and send them successfully.
source share