Android has several files with an SDK for sending email

How to connect multiple email files in Android? Is permission required to attach multiple files to an intent? I am trying to use the putParcelableArrayListExtra method (Intent.EXTRA_STREAM, ArrayList uriList), but still doubt whether the class is Uri <? extends Parcelable> or not. I can not connect the file to email.

This is my 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:")); 

and getUriListForImages () this method is defined below: -----

 private ArrayList<Uri> getUriListForImages() { ArrayList<Uri> uriList = 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++) { String file = "file://" + imageDirectoryPath + fileList[i]; Log.d(TAG, "File name for Uri :: " + file); Uri uriFile = Uri.parse(file); uriList.add(uriFile); Log.d(TAG, "Image File for Uri :: " +(file)); } } return uriList; } 

To whom, the subject and body of the letter will come, and I have images in the accident folder in sdcard (I use API level API 7), but nothing is added, even in the log frame there is no exception. OK and the file name is fine). Can someone help me solve this problem?

+4
source share
2 answers

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.

+6
source

EXTRA_STREAM says the following:

 A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent. Constant Value: "android.intent.extra.STREAM" 

You cannot pass a set of file URIs: it will simply ignore the results (as you observe).

EDIT: scratch this. I was wrong. This is a piece of code in a standard Android email client that processes multiple files.

 if (Intent.ACTION_SEND_MULTIPLE.equals(mAction) && intent.hasExtra(Intent.EXTRA_STREAM)) { ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Parcelable parcelable : list) { Uri uri = (Uri) parcelable; if (uri != null) { Attachment attachment = loadAttachmentInfo(uri); if (MimeUtility.mimeTypeMatches(attachment.mMimeType, Email.ACCEPTABLE_ATTACHMENT_SEND_INTENT_TYPES)) { addAttachment(attachment); } } } } } 

Try to do this:

 private ArrayList<Parcelable> getUriListForImages() { ArrayList<Parcelable> uriList = new ArrayList<Parcelable>(); 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++) { String file = "file://" + imageDirectoryPath + fileList[i]; Log.d(TAG, "File name for Uri :: " + file); Uri uriFile = Uri.parse(file); uriList.add(uriFile); Log.d(TAG, "Image File for Uri :: " +(file)); } } return uriList; } 
+1
source

All Articles