0

I am trying to create an email from within a method with android that contains some style but it is not working, how can achieve this - or is it not possible?

Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/html");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"test@example.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, "Sample");
        i.putExtra(Intent.EXTRA_TEXT   , Html.fromHtml("<p style='color: red'>Hello</p>"));

        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            showWarning("There are no email clients installed");
        }
Stacker-flow
  • 1,251
  • 3
  • 19
  • 39
  • [tackoverflow.com/questions/2544141/send-html-mail-using-android-intent](http://stackoverflow.com/questions/2544141/send-html-mail-using-android-intent) – M D Mar 11 '15 at 11:15
  • @MD I know how to send HTML, it is getting the CSS to be parsed that is the problem – Stacker-flow Mar 11 '15 at 11:17

1 Answers1

0

First, Html.fromHtml() does not handle style attributes. In this case, you can try <font color="red">, though I do not know if fromHtml() handles red or only supports hex color values. Or, you can use SpannableStringBuilder to color your text using a ForegroundColorSpan.

Second, you are delegating the email to a third-party app. Third-party apps do not necessarily have to support styling of the content. Hence, your red color may be dropped out by some email clients but not others.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491