0

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
GeorgeRussell
  • 91
  • 2
  • 10
  • Are you fetch document using File provider? [Check This](https://stackoverflow.com/a/28874567/6847390) may help you. – Jatin Jan 09 '21 at 15:57
  • I am using FileProvider to create the multiple URI's for the attachments. File file = new File(fileLocation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file); } else { uri = Uri.fromFile(file); } files.add(uri); – GeorgeRussell Jan 09 '21 at 16:13

0 Answers0