【问题标题】:attachment not added to email intent附件未添加到电子邮件意图
【发布时间】:2017-04-11 05:26:36
【问题描述】:

我想将一些照片文件添加到电子邮件意图中。 意图正在正常启动。

问题:附件未显示,例如在 GMail 应用程序中。我没有收到任何错误消息。 问题可能出在哪里?

我已经根据post 中的建议更改了我的代码,但我的代码似乎仍然无法正常工作。

我从照片对象收到的文件路径:file:///storage/emulated/0/Pictures/SMSCloudImages/IMG_20161127_121011.jpg 它应该是正确的路径,因为我可以在图库中显示图像。

   Uri uri = Uri.parse("mailto:" + "someone@mail.com")
                .buildUpon()
                .appendQueryParameter("subject", subject)
                .appendQueryParameter("body", body)
                .build();

        List<Photo> photoList = new ArrayList<>();
        photoList.addAll(databaseHandler.getPhotos(qReport.getId()));

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);

        Intent intentPick = new Intent();
        intentPick.setAction(Intent.ACTION_PICK_ACTIVITY);
        intentPick.putExtra(Intent.EXTRA_TITLE, getResources().getString(R.string.q_report_launch_mail_text));
        intentPick.putExtra(Intent.EXTRA_INTENT, emailIntent);

        for (Photo photo: photoList) {
            intentPick.putExtra(Intent.EXTRA_STREAM, Uri.parse(photo.getName()));
        }

        this.startActivityForResult(intentPick, REQUEST_CODE_MY_PICK);

【问题讨论】:

    标签: android file email android-intent


    【解决方案1】:

    记得给android manifest添加正确的权限(读写):

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    

    【讨论】:

      【解决方案2】:

      这是我使用的代码:

      //how hany picture you want the user to upload
      private static final int SELECT_PICTURE = 1;
      
      public void grabImg(){
          Intent intent = new Intent();
          intent.setType("image/*");
          intent.setAction(Intent.ACTION_GET_CONTENT);
          startActivityForResult(Intent.createChooser(intent,
                  "Select Picture"), SELECT_PICTURE);
      }
      
      Uri uri = null;
      
      protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
          super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
              if(resultCode == RESULT_OK){
                  Uri selectedImage = imageReturnedIntent.getData();
                  uri = selectedImage;
      
              }
      }
      
      //This is triggered on a button click
      
      String subject = Suggest.getText().toString();
                  String rating = String.valueOf(RateBar.getRating());
                  String to ="xxxxx@mail.com"; //destination
                  String message = UserInput.getText().toString();
                  String body = message;
                  Intent email = new Intent(Intent.ACTION_SEND);
                  email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
                  email.putExtra(Intent.EXTRA_SUBJECT, subject);
                  email.putExtra(Intent.EXTRA_TEXT, body);
                  email.putExtra(Intent.EXTRA_STREAM, uri);
                  email.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                  //need this to prompts email client only
                  email.setType("message/rfc822");
      
                  startActivity(Intent.createChooser(email, "Choose an Email client :"));
      

      【讨论】:

        猜你喜欢
        • 2015-03-06
        • 1970-01-01
        • 2016-07-30
        • 1970-01-01
        • 2019-03-14
        • 1970-01-01
        • 1970-01-01
        • 2015-11-07
        相关资源
        最近更新 更多