与可点击的链接Android的份额意图 [英] Android share Intent with clickable link
问题描述
我已经看过了网络上,但还没有找到一个适合我的具体需求的解决方案。我正在寻找一种方式来分享一杯羹的意图,提供了一个可点击的链接信息,是这样的:
I have looked around the web but have yet to find a solution that fits my specific need. I am looking for a way to share information with a share intent that provides a clickable link, something like:
看看这篇新闻报道
我已经成功地建立了在我的Android应用程序共享的意图看起来是这样的:
I have successfully set up a share intent in my android app which looks like this:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Text");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check out this news article" + "\n\n" + getResources().getText(R.string.shared_via));
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Share this article with..."));
我的字符串资源如下所示:
My string resource looks like this:
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>
的共享功能,因为它应该然而,在电子邮件,Twitter等链接时将忽略共享和鸣叫只显示纯文本是这样的:
The sharing functions as it should however when shared in an Email, Twitter, etc. the link is ignored and the tweet shows only plain text like this:
我试着用MIME类型玩耍,但仍然没有雪茄。反正是有共享时得到吉米的新闻应用程序点击?我比感激更多的任何和所有帮助和或提示。
I tried playing around with the MIME type, but still no cigar. Is there anyway to get "Jimmy's News App" clickable when shared? I am more than greatful for any and all help and or tips.
在此先感谢!
推荐答案
首先,我没有想到你的项目甚至建立,作为字符串资源不支持任意的HTML标记。唯一有文字记录的是&LT; B&GT;
,&LT; I&GT;
和&LT; U&GT;
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.
这篇关于与可点击的链接Android的份额意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!