且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

与可点击的链接Android的份额意图

更新时间:2023-01-27 18:55:00

首先,我没有想到你的项目甚至建立,作为字符串资源不支持任意的HTML标记。唯一有文字记录的是​​< B> < I> < U>

First, I wouldn't have expected your project to even build, as string resources do not support arbitrary HTML tags. The only documented ones are <b>, <i>, and <u>.

其次,即使它支持任意的HTML标签,您是从跨区的getText()$ C $转换回C>)转换成纯字符串,这将删除该格式。

Second, even if it does support arbitrary HTML tags, you are converting it back from a Spanned (getText()) into a plain string, which will remove that formatting.

要解决这两个问题,要么移到该字符串转换成Java(毕竟,它不喜欢你的i18n去,硬codeD英语在code段其他地方),或包裹在一个字符串内容 CDATA (同​​时修复你的破HTML,使用的href &LT; A&GT; 属性):

To overcome both problems, either move that string into Java (after all, it's not like you have i18n going, with hardcoded English elsewhere in your code snippet), or wrap the string content in a CDATA (while also fixing your broken HTML, to use href for the <a> attribute):

<string name="shared_via"><![CDATA[via <a href="http://google.com">Jimmy's News App</a>]]></string>

在这一点上,如果你看看你的连接字符串,它应该看起来像准HTML源代码:

At this point, if you look at your concatenated string, it should look like quasi-HTML source:

Check out this news article

via <a href="http://google.com">Jimmy's News App</a>

接下来,当你发送过HTML,你是它声明为纯文本。因此,许多应用程序将其当作纯文本,并可能忽略标签显示了原始的HTML做任何事情。欢迎您来尝试的text / html 作为一个MIME类型,看看你得到更好的结果。

Next, while you are sending over HTML, you are declaring it as plain text. Many apps will therefore treat it as plain text, and may do anything from ignoring the tag to showing the raw HTML. You are welcome to try text/html as a MIME type and see if you get better results.

最后,没有要求任何应用程序实际兑现你的链接。 ACTION_SEND 是一个请求,而不是一个命令。有第三方应用程序如何使用HTML,你寄过来没有规则,所以你会得到不同的从应用不同的结果。

Finally, there is no requirement that any app actually honor your links. ACTION_SEND is a request, not a command. There are no rules for how third-party apps use the HTML that you send over, and so you are going to get varying results from varying apps.