在Android中发送HTML邮件使用<表>等 - 是真的没有相对内置意图的方式? [英] Sending html email in android using <table>, etc. - is there really no relatively built-in Intent way?

查看:642
本文介绍了在Android中发送HTML邮件使用<表>等 - 是真的没有相对内置意图的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了好位来自机器人发送HTML电子邮件的限制。所有的建议发送HTML邮件似乎只是通过Htm​​l.fromHtml(yourHtmlString)的意图是Intent.EXTRA_TEXT。这适用于一些基本的标签 - 粗体,斜体 - 但不会像HTML表什么

看起来你可以尽量延长一些使用HTML的功能或实现自己的taghandler,但我想知道,如果没有一个更根本的限制,这将迫使你做的东西完全不同的(像邮件API或东西)。

我建议这样做的原因是因为,尽可能的意图本身知道,Html.fromHtml(等等)仅仅是一个的CharSequence,如果你拨打的CharSequence接口的方法,这个对象上,你看不到任何HTML东西(至少我没有)。所有的HTML /标签的东西似乎被包裹在这Html.fromHtml实际返回的SpannableStringBuilder ...我想知道如果Gmail应用看起来在被窝里看什么的CharSequence真的是再能处理几个标签,这意味着在对的事情让你的应用程序的身边做任何事情没有希望/欺骗Gmail应用处理以外的任何大胆的更复杂,斜体等。

我已经看过原始邮件的Gmail应用程序实际发送,它会自动发送既有纯文本/无标签,文本/ HTML版本标签的数量有限。我甚至尝试坚持在一些逃脱了,可能最终地转化为实际的标签在电子邮件的文本/ HTML部分html标签,但可惜他们住逃脱......当然这将是一个有点哈克。

总之,对于任何人谁可能已经考虑过这多了,我想这样做的默认的Andr​​oid发送HTML邮件额外的确认功能,将让你令人发狂的接近你可能需要,但最终你已经得硬着头皮执行了大量的低层次的东西你自己(如<一个href="http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-ap">Sending电子邮件在Android中使用JavaMail API不使用默认的Andr​​oid应用程序(内建电子邮件应用程序),这意味着你必须处理PW的东西,等等)。

请注意(后): 我包了SpannableStringBuilder从Html.fromHtml返回与扩展SpannableStringBuilder,并通过了该意图监听呼叫跨越式界面的自定义类。原来,当事情写入发送到电子邮件的意图包裹,TextUtils.writeToParcel做了一些特殊的检查,首先检查是否是CharSequence的跨接的一个实例,然后要求深挖粗体/斜体的东西跨度(通过spanned.getSpans)。不过,我看不出有什么明显的希望作出的修改得到的东西简单,只要在那里处理表/ TD标签。我甚至尝试改变我SpannableStringBuilder的子类的toString()返回一些原始表的HTML,看看会发生什么,但它得到了包裹,写作过程中逃脱别的地方出现了下滑。

和更多(后): TextUtils.writeToParcel(CharSequence的CS,包裹磷,...)会,如果CS是跨区的一个实例,写那些跨度只有当他们实施ParcelableSpan界面......这是一种特殊的Parcelable的将作为文本跨距和对象只能使用code在框架中;它不用于应用程序实现自己Parcelable跨距。所以,即使你想挂接到这一点,并编写自己的处理表格标记或什么的,这似乎是劝阻。男人我希望hackbod会权衡在这里的东西很明显我已经错过了。

解决方案
  

这适用于一些基本的标签 - 粗体,斜体 - 但不会像HTML表什么

这是电子邮件客户端,最有可能的功能。不是所有的电子邮件客户端可以创作任意HTML,在任何平台上。因此,在Mozilla Thunderbird中出现,让你创建表的HTML电子邮件时,Gmail不会(至少 - 我是没有看到它的消息撰写窗口的一个选项)。

  

我想知道,如果没有一个更根本的限制,这将迫使你做的东西完全不同。

除非你写你自己的电子邮件客户端,扩展需要,使几类的TextView 的EditText 来处理HTML表(它的办法不仅仅是 HTML 类以上)对你没好处。

  

和我想知道如果Gmail应用看起来在被窝里看什么的CharSequence真的是再能处理一些标签

的TextView 的EditText 可以处理一些标签,排队大概什么 HTML 可以解析/生成和 SpannedString 可以重新present。

没有的,可以处理的HTML表。和JavaScript。也不CSS。和 IFRAME 或任何其他标​​记。

  

但最终你得硬着头皮执行了大量的低层次的东西你自己

我会问自己是否从手机发送的桌子HTML邮件直接是值得的开始。你可以使用表格从你的服务器使用Web服务接口发送HTML邮件,也可以从手机发送HTML邮件SANS表。无论是那些要求你收集的PW的东西。

I have read a good bit on the limitations of sending html email from android. All suggestions to send html email seem to be to just pass Html.fromHtml(yourHtmlString) to the intent as Intent.EXTRA_TEXT. This works for a few basic tags - bold, italic - but won't for anything like an html table.

It looks like you could try to extend some of the functionality of either Html or implement your own taghandler, but I am wondering if there is not a more fundamental limitation that will force you to do something completely different (like with the mail api or something).

The reason I suggest this is because, as far as the intent itself knows, Html.fromHtml(blah) is simply a charsequence, and if you call the methods on the charsequence interface on this object you don't see any html stuff (at least I didn't). All of the html/tag stuff seems to be wrapped up in the SpannableStringBuilder that Html.fromHtml actually returns... and I am wondering if the gmail app looks under the covers to see what the charsequence really is and then can handle a few tags, which means that there is no hope in doing anything on your app's side of things to get/trick the gmail app to handle anything more complicated than bold, italic, etc.

I have looked at the raw email the gmail app actually sends, and it automatically sends both a text/plain with no tags, and the text/html version with the limited number of tags. I even tried sticking in some escaped html tags that might ultimately get converted to actual tags in the text/html part of the email, but alas they stayed escaped... and that would of course be a bit hacky.

Anyway, for anyone who might have looked into this more, I wanted to do an additional confirmation that the default android "send html email" functionality will get you maddeningly close to what you might need, but in the end you've got to bite the bullet and implement a lot of lower level stuff yourself (such as Sending Email in Android using JavaMail API without using the default android app(Builtin Email application) , which means you've got to deal with the pw stuff, etc.).

Note (later): I wrapped the SpannableStringBuilder returned from Html.fromHtml with a custom class that extended SpannableStringBuilder and passed that to the intent to listen for calls to the Spanned interface. It turns out that when things are written to the parcel that is sent to the email intent, TextUtils.writeToParcel does some special checking to root out the bold/italic stuff by first checking if the CharSequence is an instance of Spanned, and then asking for the spans (via spanned.getSpans). Nevertheless, I see no obvious hope in making the modifications to get something as simple as table/td tags handled in there. And I even tried modifying the toString() of my subclass of SpannableStringBuilder to return some raw table html to see what would happen, but it gets escaped somewhere else down there in the parcel-writing process.

And More (Later): TextUtils.writeToParcel(CharSequence cs, Parcel p,...) will, if cs is an instance of "Spanned", write those spans only if they implement the "ParcelableSpan" interface... which is "A special kind of Parcelable for objects that will serve as text spans" and "can only be used by code in the framework; it is not intended for applications to implement their own Parcelable spans". So, even if you wanted to hook into this and write your own to handle table tags or whatever, it seems to be discouraged. Man I wish hackbod would weigh in here with something obvious I've missed.

解决方案

This works for a few basic tags - bold, italic - but won't for anything like an html table.

That is a function of the email client, most likely. Not all email clients can author arbitrary HTML, on any platform. So, while Mozilla Thunderbird appears to let you create an HTML mail with a table, Gmail does not (leastways, I don't see an option for it in the message-compose window).

I am wondering if there is not a more fundamental limitation that will force you to do something completely different

Unless you write your own email client, extending the several classes needed to allow TextView and EditText to handle HTML tables (it's way more than just the Html class) will do you no good.

and I am wondering if the gmail app looks under the covers to see what the charsequence really is and then can handle a few tags

TextView and EditText can "handle a few tags", lining up roughly with what Html can parse/generate and SpannedString can represent.

None of that can handle an HTML table. Nor JavaScript. Nor CSS. Nor iframe or any number of other tags.

but in the end you've got to bite the bullet and implement a lot of lower level stuff yourself

I'd start by asking yourself whether sending HTML mail with tables from the phone directly is worth it. You could send HTML mail with tables from your server using a Web service interface, or you could send HTML mail sans tables from the phone. Neither of those would require you to collect "the pw stuff".

这篇关于在Android中发送HTML邮件使用&LT;表&gt;等 - 是真的没有相对内置意图的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆