Html无法在Gmail等电子邮件客户端中呈现

时间:2017-06-15 11:09:17

标签: android email android-intent

  

我使用Html.fromHtml呈现HTML并将其传递给emailIntent。

                        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                                "mailto","", null));

                        ///emailIntent.setType("text/html");
                        emailTemplate = emailTemplate.replaceAll("(\r\n|\n)", "<br />").trim();

                        emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");

                        Spanned shareBody = null;//remove it's instance...

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            Spanned spanned = Html.fromHtml(emailTemplate ,Html.FROM_HTML_MODE_LEGACY);
                            shareBody = spanned;
                            ///emailTemplate = spanned.toString();
                        }
                        else
                        {
                            Spanned spanned =  Html.fromHtml(emailTemplate);
                            shareBody = spanned;
                            ///emailTemplate = spanned.toString();
                        }

                        emailIntent.putExtra(Intent.EXTRA_TEXT, shareBody);//emailTemplate);
                        mContext.startActivity(Intent.createChooser(emailIntent, "Send email..."));

其中emailTemplate是

"\u003ctable id=\"pltrlText\" style=\"width:100%; display:block; margin:0px; padding:0px;\"\u003e \u003ctbody style=\"display: block;\"\u003e \u003ctr style=\"display: block; margin: 0px 5px 30px 5px; \"\u003e \u003ctd style=\"font-family: \u0027OpenSansRegular\u0027, Arial; color: #444444; font-size: 14px; \"\u003e HI[Razi] \u003c/td\u003e \u003c/tr\u003e \u003ctr style=\"display: block; margin: 0px 5px 30px 5px; \"\u003e \u003ctd style=\"font-family: \u0027OpenSansRegular\u0027, Arial; color: #444444; font-size: 14px; \"\u003e We are happy to offer you solutions, that make a positive impact on your business. We are happy to offer you solutions, that make a positive impact on your business. We are happy to offer you solutions, that make a positive impact on your business. We are happy to offer you solutions, that make a positive impact on your business.We are happy to offer you solutions, that make a positive impact on your business. We are happy to offer you solutions, that make a positive impact on your business. \u003c/td\u003e \u003c/tr\u003e \u003c/tbody\u003e \u003c/table\u003e"

没有显示下一行,也没有应用任何样式。我究竟做错了什么。还尝试使用String和Spanned。

没有风格像颜色和背景一样

  

但同样适用于IOS app gmail客户端和其他人。

1 个答案:

答案 0 :(得分:0)

  

我做错了什么。

您假设您可以使用任意HTML。在任何平台(包括Web邮件)上,很少有电子邮件客户端支持电子邮件作曲家中的任意HTML。

对于Android,一般情况下,期望仅限于Html.fromHtml()Html.toHtml()支持的代码。值得注意的是,鉴于你非常奇怪的模板:

  • <table>不受支持(以及<tr><td>
  • 大多数style位不受支持
相关问题