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?
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 :
Visit google
Use a href
tag
and set Text here with Html.fromHtml();
and set to textview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With