Har*_*nan 4 android android-intent android-sharing
我想共享一个文本,点击用户将通过android共享意图导航到一个URL.
例如:
"访问谷歌了解更多信息."
在上面的文字中,点击谷歌后,用户将被重定向到google.com.我需要实现这样的事情,而不是向用户显示完整的URL.我试过的是使它与href的html链接不起作用.
那么,我该如何实现呢?
您必须使用类型plain textie,:
intent.setType("text/plain");
Run Code Online (Sandbox Code Playgroud)
将类型设置为html,如下所示:
intent.setType("text/html");
Run Code Online (Sandbox Code Playgroud)
它会工作的.
因此,您可以使用它来共享html文本:
String textToShare = "Visit <a href=\"http://www.google.com\">google</a> for more info.";
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "sample");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(textToShare));
startActivity(Intent.createChooser(intent, "Share"));
Run Code Online (Sandbox Code Playgroud)
输出:
以下是Gmail应用的截图:
Sac*_*ise -1
尝试这样:
使用文本视图选择和长按侦听器来调用共享意图。否则你可以使用android spannable textview。
请参阅此链接以通过谷歌搜索获取可跨文本视图:http://androidcocktail.blogspot.in/2014/03/android-spannablestring-example.html
Uri uri = Uri.parse("http://www.google.com/#q=selected word here");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7343 次 |
| 最近记录: |