Android通过可点击链接分享意图

Android通过可点击链接分享意图,android,android-intent,social-networking,android-sharing,Android,Android Intent,Social Networking,Android Sharing,我环顾了网络,但还没有找到适合我具体需要的解决方案。我正在寻找一种共享信息的方式,这种方式提供了一个可点击的链接,比如: 看看这篇新闻文章 通过 我已在我的android应用程序中成功设置了共享意图,如下所示: Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Text"); shareI

我环顾了网络,但还没有找到适合我具体需要的解决方案。我正在寻找一种共享信息的方式,这种方式提供了一个可点击的链接,比如:

看看这篇新闻文章

通过

我已在我的android应用程序中成功设置了共享意图,如下所示:

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..."));
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>
我的字符串资源如下所示:

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..."));
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>
通过吉米的新闻应用程序
但是,当在电子邮件、Twitter等中共享时,共享的功能应该是正常的。链接被忽略,tweet仅显示如下纯文本:

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..."));
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>

我试着玩哑剧,但还是没有雪茄。在共享时,是否可以点击“Jimmy的新闻应用程序”?我非常感谢任何和所有的帮助和/或提示


提前谢谢

首先,我甚至不希望您的项目生成,因为字符串资源不支持任意HTML标记。只有
记录在案

第二,即使它确实支持任意HTML标记,您也要将它从
跨距
getText()
)转换回普通字符串,这将删除该格式

要解决这两个问题,可以将该字符串移动到Java中(毕竟,它不像i18n,代码段中的其他地方有硬编码英语),或者将字符串内容包装到
CDATA
(同时修复损坏的HTML,使用
href
处理
]>
此时,如果您查看连接的字符串,它应该看起来像准HTML源代码:

Check out this news article

via <a href="http://google.com">Jimmy's News App</a>
查看这篇新闻文章
通过
接下来,当您通过HTML发送时,您将其声明为纯文本。因此,许多应用程序会将其视为纯文本,并且可能会执行任何操作,从忽略标记到显示原始HTML。欢迎您尝试将
text/HTML
作为MIME类型,并查看是否获得更好的结果

最后,不要求任何应用程序真正尊重您的链接。
ACTION\u SEND
是一个请求,而不是命令。对于第三方应用程序如何使用您发送的HTML,没有任何规则,因此您将从不同的应用程序中获得不同的结果