微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Intent 时如何将附件加载到 Gmail?

如何解决使用 Intent 时如何将附件加载到 Gmail?

我有一个应用程序,我想在其中发送包含多个 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 = [content://com.grgapps.checkingin.provider/external/Documents/allContactsAuditReport.pdf,content://com.grgapps.checkingin.provider/external/Documents/contactAppUsersAuditReport.pdf

解决方法

我知道我迟到了,但这对我认为的人有用

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。