使用intent时如何将附件加载到gmail?

ikfrs5lh  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(311)

我有一个应用程序,我想发送多个pdf附件电子邮件。一切似乎都正常工作,我没有得到任何例外,但当gmail加载,附件不包括在内。
我回顾了stackoverflow和其他网站上的许多问题,并跟踪/测试了许多解决方案,但都没有奏效。当然需要帮助。
以下是发送电子邮件的代码。

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);
            }
        }

这是要添加的附件的“files”元素中包含的数据

files = [content://com.grgapps.checkingin.provider/external/Documents/allContactsAuditReport.pdf, content://com.grgapps.checkingin.provider/external/Documents/contactAppUsersAuditReport.pdf

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题