2017-06-15 108 views
-1

我使用Html.fromHtml呈現HTML並將其傳遞給emailIntent。Html無法在電子郵件客戶端中呈現,如Gmail

     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應用Gmail客戶端和其他人了。

+0

'我在做什麼錯了.. 。'你正在將標記字符('<' and '>')轉換爲它們的Unicode代碼。 –

回答

0

我在做什麼錯。

你假設你可以使用任意的HTML。在任何平臺上(包括Web郵件),很少有電子郵件客戶端在他們的電子郵件作曲者中支持任意的HTML。

在Android的情況下,一般來說,預計僅限於支持Html.fromHtml()Html.toHtml()的標籤。值得注意的是,鑑於你很奇怪的模板:

  • <table>不支持(連同<tr><td>
  • 你的大部分style位,不支持
+0

但同樣適用於IOS應用程序Gmail客戶端和其他人。 – Nepster

+1

@Nepster:iOS不是Android。 – CommonsWare

相關問題