0

I'm trying to embed HTML code to android gmail. I've search on SO for answers. Most of them are outdated. Some information like colors I want to send to the user. I call gmail intent from my app and insert this HTML for testing purposes:

sendIntent.setType("text/html");
    sendIntent.setData( Uri.parse( "mailto:"+receivers.get( 0 ) ) );
    sendIntent.putExtra( Intent.EXTRA_EMAIL, "contact@myemail.com" );
    sendIntent.putExtra( Intent.EXTRA_SUBJECT, getSubject() );
    if( Build.VERSION.SDK_INT >= 24 ) {
        sendIntent.putExtra(Intent.EXTRA_TEXT, message+"\n"+Html.fromHtml("<html><body bgcolor='#ff0000'><table><tr><td bgcolor=\"#ff0000\">aaa</td><td>aaa</td></tr></table></body></html>", Html.FROM_HTML_MODE_LEGACY));
    }
    else{
        sendIntent.putExtra(Intent.EXTRA_TEXT, message+"\n"+Html.fromHtml("<html><body bgcolor='#ff0000'><table><tr><td bgcolor=\"#ff0000\">aaa</td><td>aaa</td></tr></table></body></html>" ) );
    }

Strings "aaa" are written but nothing more. Cell colors or even the table aren't displayed. Is this a gmail restriction?

learner
  • 1,311
  • 3
  • 18
  • 39
  • Possible duplicate of [Send HTML mail using Android intent](http://stackoverflow.com/questions/2544141/send-html-mail-using-android-intent) – kandroidj Jan 11 '17 at 18:16
  • @inner_class7 This was one of the outdated answers that I mentioned before. Solutions provided there doesn't work. – learner Jan 11 '17 at 18:27

1 Answers1

0
message+"\n"+Html.fromHtml("<html><body bgcolor='#ff0000'><table><tr><td bgcolor=\"#ff0000\">aaa</td><td>aaa</td></tr></table></body></html>"

You parse some HTML to get a Spanned, then convert that Spanned back into a plain String for concatenation, removing all the formatting. Use TextUtils.concat(), not +, to try to retain some formatting.

However:

  • Tables are not supported by Html, at least prior to API Level 24 (and I don't think the updated version supports them either)

  • There is no requirement for any email client to pay any attention to your formatting

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Tried to insert onyl HTML before. Any formatting is displayed. After answers provided. I'll try another approach. – learner Jan 11 '17 at 18:40