I have an app where I want to send an email with multiple pdf attachments. Everything seems to work correctly and I do not get any exceptions, but when Gmail loads, the attachments are not included.
I have reviewed many questions on stackoverflow and other sites and have followed/tested many solutions, but none have worked. Sure could use some help.
The following is the code for sending the email.
public void eMailDocument(ArrayList<Uri> files) {
try {
Log.i(TAG, "MainViewModel eMailDocument: files = " + files);
Intent intent = new Intent(ACTION_SEND_MULTIPLE);
List<Intent> emailAppLauncherIntents = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> emailApps = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);
for (ResolveInfo resolveInfo : emailApps) {
String packageName = resolveInfo.activityInfo.packageName;
Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
emailAppLauncherIntents.add(launchIntent);
}
mSubjectLine = "CheckingIn app contact audit reports";
Intent chooserIntent = Intent.createChooser(new Intent(ACTION_SEND_MULTIPLE), "Select email app:");
chooserIntent.setAction(ACTION_SEND_MULTIPLE);
chooserIntent.setType("application/pdf");
//chooserIntent.setData(Uri.parse("mailto:"));
chooserIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mCurrentUserEmailAddress});
chooserIntent.putExtra(Intent.EXTRA_SUBJECT, mSubjectLine);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
chooserIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, emailAppLauncherIntents.toArray(new Parcelable[emailAppLauncherIntents.size()]));
context.startActivity(chooserIntent);
} catch(Exception e) {
System.out.println("is exception raises during sending mail"+e);
}
}
This is the data contained in the "files" element for the attachments to be added
files = [content://com.grgapps.checkingin.provider/external/Documents/allContactsAuditReport.pdf, content://com.grgapps.checkingin.provider/external/Documents/contactAppUsersAuditReport.pdf
I know that I am late but this works for someone I think
Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
ei.setType("plain/text");
ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
ei.putExtra(Intent.EXTRA_SUBJECT, "That one works");
ArrayList<String> fileList = new ArrayList<String>();
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0;i<fileList.size();i++)
{
File fileIn = new File(fileList.get(i));
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.