Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 451
Hari Krishnan Avatar asked Jul 12 '16 07:07

Hari Krishnan


2 Answers

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

like image 124
Ashish Ranjan Avatar answered Sep 19 '22 04:09

Ashish Ranjan


Visit google

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

like image 33
JAAD Avatar answered Sep 21 '22 04:09

JAAD