Hari Krishnan
Hari Krishnan

Reputation: 6302

How to share a text link via text intent?

I want to share a text clicking on which the user will navigate to a url via android share intent.

For example:

"Visit google for more info."

In above text, on clicking google, user will be redirected to google.com. I need to achieve something like this instead of showing the user the complete url. What i have tried is making it an html link with href which doesnt work.

So, How should i achieve it?

Upvotes: 6

Views: 15548

Answers (3)

Ashish Ranjan
Ashish Ranjan

Reputation: 5543

You must be using the type as plain text i.e, :

intent.setType("text/plain");

set the type to html like this :

intent.setType("text/html");

and it'll work.

So, you can use this to share a html text :

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"));

OUTPUT :

Here's a screenshot from the Gmail app :

Screenshot from Gmail app

Upvotes: 11

JAAD
JAAD

Reputation: 12379

Visit google

Use a href tag and set Text here with Html.fromHtml(); and set to textview

Upvotes: 2

Sackurise
Sackurise

Reputation: 2814

try like this:

use text view selection and long press listener to call share intent. otherwise you can use android spannable textview.

Refer this link for spannable textview with google search: 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);

Upvotes: -1

Related Questions