【问题标题】:How to send email with Attachment(Image)如何发送带附件的电子邮件(图片)
【发布时间】:2013-01-07 17:57:37
【问题描述】:

我尝试了两种方法来send email 使用图像附件。附件在撰写主题时显示,在发送该电子邮件后的所有内容都显示在收件人处,它只显示subject & Body 只是没有用户获得的附件。我是不明白下面我的代码有什么问题是我的代码。请给我任何建议来完成这项任务。

类型 1:-

   Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
   picMessageIntent.setType("image/jpeg");
   File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature
   picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));//screenshotUri );//Uri.fromFile(new File("downloadedPic"))); //Uri.fromFile(downloadedPic)); // Uri.fromFile(new File("/path/to/downloadedPic")));
        startActivity(Intent.createChooser(picMessageIntent, "Share image using"));

类型 2:

 ArrayList<Uri> uris = new ArrayList<Uri>();   
 Uri u;        
 Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
 picMessageIntent.setType("image/jpeg");
 File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature           
 if(downloadedPic.exists())
    {
      Uri u1 = Uri.fromFile(downloadedPic);
      uris.add(u1);
      picMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      startActivity(picMessageIntent);
    }

【问题讨论】:

    标签: android image sendmail


    【解决方案1】:

    这里有一些可以帮助你的东西。确保以正确的方式拼写图像文件路径。不要忘记“/”分隔符(尝试获取路径日志)。另外,请确保该文件存在。

    /** ATTACHING IMAGE TO EMAIL AND SENDING EMAIL  */
            Button b1 = (Button)findViewById(R.id.finalsectionsubmit);
            b1.setOnClickListener(new View.OnClickListener() {
    
          @Override
          public void onClick(View v) {
    
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    //        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailSignature);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, toSenders);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subjectText);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageText+"\n\n"+emailSignature); 
    
            emailIntent.setType("image/jpeg");
            File bitmapFile = new File(Environment.getExternalStorageDirectory()+
                "/"+FOLDER_NAME+"/picture.jpg");
            myUri = Uri.fromFile(bitmapFile);
            emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
    
    
            startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
            eraseContent();
            sentMode = true;
          }
        });
    

    【讨论】:

    • 这里面,什么是eraseContent()和sendmode
    • eraseContent() 是一个私有方法,而 sendMode 是一个标志。您不需要他们发送电子邮件。上面发布的代码来自一个 Android 项目。
    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2016-08-23
    • 2015-08-28
    • 1970-01-01
    • 2014-04-23
    相关资源
    最近更新 更多