【问题标题】:Send Image with email Intent not displaying发送带有电子邮件意图的图像未显示
【发布时间】:2017-06-18 00:37:30
【问题描述】:

我正在尝试通过 ACTION_SEND 从我的应用程序的数据库中发送一封电子邮件。一切正常,所有包含用户详细信息的字段都使用 html 在电子邮件正文中正确格式化。但是,当我还需要发送图像时(使用 android 上的标准内置电子邮件客户端),我会收到一个显示“无法附加文件”的祝酒词

我已经搜索并尝试了 SO 的各种解决方案,但没有一个对我有帮助。

这就是我所拥有的:

 Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);

    String aEmailList[] = {"user@example.com", "user1@example.com"};
    messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    messageIntent.putExtra(Intent.EXTRA_CC, new String[]{"user2@example.com", "user3@example.com"});
    messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

    messageIntent.setType("text/html");
    messageIntent.setType("image/png");
    messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    Log.v(getClass().getSimpleName(), "simageUri=" + Uri.parse("file://"+ image));
    messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ image));
    startActivity(messageIntent);
}

现在图像是文件保存在我的数据库中的位置。我已经尝试过image.getAbsolutePath 但这会因空指针异常而崩溃

在我的 String.xml 中,我必须输入电子邮件的正文。

<string
    name="feedbackmessagebody_format">
    <![CDATA[
    <html>
    <head>
   <style>
   table {
  border-collapse: collapse;
   }

    td, th {
    border: 1px solid black;
    padding: 3px;
    }
   </style>
    </head>
   <body>
   <table>
   <col width="300">
  <tr>
  <th>Field</th>
  <th>Description</th>
  </tr>
  <tr>
  <td><b>Image: </b></td>
  <td>%22$s</td>
  </tr>
  </table>

  </body>
  </html>
   ]]></string>

%22$s 是我的电子邮件正文中的字段数,它指向

  final ImageView feedbackField19 = (ImageView) findViewById(R.id.imageA);
  String feedback22 = feedbackField19.getDrawable().toString();

不确定我在这里缺少什么?

【问题讨论】:

  • "我尝试了 image.getAbsolutePath,但是由于空指针异常而崩溃" -- 然后image 为空,"file://"+ image 将为file://null,这不是一个有效的文件系统您的图像的路径。另请注意,您调用了两次setType()(仅支持第二次),并且应用不需要同时支持EXTRA_TEXTEXTRA_STREAM
  • @CommonsWare 谢谢。我让它工作了,但只是作为附件,但真的很想在电子邮件正文中显示图像
  • 将图像上传到 Web 服务器。然后,使用该图像的 URL。
  • @CommonsWare,谢谢,但我没有网络服务器,但会制定计划。谢谢

标签: android sqlite email


【解决方案1】:
    String recepientEmail = ""; // either set to destination email or leave empty
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:" + recepientEmail));
    intent.putExtra(Intent.EXTRA_SUBJECT,"email subject");
    intent.putExtra(Intent.EXTRA_TEXT,message);
    intent.putExtra(Intent.EXTRA_STREAM,filePath);
    startActivity(intent);

【讨论】:

猜你喜欢
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 2012-01-31
  • 2015-07-29
  • 2013-11-11
  • 2012-04-07
  • 1970-01-01
相关资源
最近更新 更多