4

From an Android app, I'm trying to send an email with an HTML body with an embedded img. From what I've read, the following should work. The email is received with HTML bold tags working correctly etc, however the img is replaced with [OBJ]. My logging tells me that I do indeed get a Drawable with the correct dimensions etc, so it seems that the local email client is not understanding the image in the Spannable. Is there some trick such as images need to come from "content:" URIs? thanks!

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, "Sample subject");
i.setType("text/html");
Spanned html =
    Html.fromHtml(
        "<html><body>h<b>ell</b>o<img src='http://www.pp.rhul.ac.uk/twiki/pub/TWiki/GnuPlotPlugin/RosenbrockFunctionSample.png'>world</body></html>",
        new ImageGetter() {
            public Drawable getDrawable(String url) {
                InputStream s = (InputStream) (new URL(url)).getContent();
                Drawable d = Drawable.createFromStream(s, null);
                LogUtil.debug(this, "Got image: " + d.getClass() + ", " + d.getIntrinsicWidth() + "x" + d.getIntrinsicHeight());
                d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                return d;
             }
        ),
        null
    );
i.putExtra(Intent.EXTRA_TEXT, html);
startActivity(Intent.createChooser(i, "Send email"));
Nate
  • 31,017
  • 13
  • 83
  • 207
nickk
  • 41
  • 2
  • Possible duplicate http://stackoverflow.com/questions/3148486/embedding-image-in-email-in-android – Cheryl Simon Aug 17 '10 at 23:37
  • We've seen this question a few times these last few weeks, but it seems that sometimes the solution suggested in this post is simply not working and a blank square is displayed... – Sephy Aug 18 '10 at 07:27
  • fyi ... I am trying this from simulator. is it possible that this is the problem?! --nickk – nickk Aug 18 '10 at 17:27
  • Hi @nikk, were you able to solve this? I am also trying to do the same thing and having no success at the moment. :( – Zarah Oct 27 '10 at 08:40

0 Answers0