Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass hyperlink to Gmail in Intent ACTION_SEND?

May be this question is already asked or duplicate of another question, but I didn't get any solution for my search. Here are the links which I followed for my question: Link1 Link2

Actually, my question is related to sharing HTML text in android default intent with an ACTION_SEND. When I am trying to create a hyperlink to URL with different value then it is showing a simple text of value. That is not clickable as a link.

Here is how I am doing:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
String link = "https://www.android.com/";
String linkValue = "Click Me";
String body1 = "<a href=\"" + link + "\">" + link+ "</a>";//I don't want this
String body2 = "<a href=\"" + link + "\">" + linkValue + "</a>";//This is not working
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body2));
startActivity(Intent.createChooser(intent, "Share With"));

For body2: When I share the text using Gmail then in email hyperlinked text will come as a normal text. Simply "Click Me". I checked it on desktop browser also. But there also it is same. I checked this text in Inspect Element(You can get Inspect Element of a browser page like: Right click on browser page>> In popup window click at the bottom Inspect OR refer Inspect Element) format and found there was no tag for hyperlink text.

For body1: It's working and I got the URL as a hyperlink in the email, but I got the URL as a hyperlink I don't want to show the same URL in email rather than there should be some hint value as body2 format. This format can be achieved by direct URL sharing in the body no need of tag.

enter image description here

So finally my search is, Is there any way in Android for sharing hyperlink text with different hint value rather than as of link(URL).

like image 418
Ready Android Avatar asked Dec 20 '16 13:12

Ready Android


2 Answers

I suggest you use a string resource instead of a Java string, it's generally and good practice and that way you won't have to escape the " either. And with the HTML data you'll have to wrap it in CDATA.

XML:

<string name="readyandroid"><![CDATA[<a href="https://readyandroid.wordpress.com/">readyandroid</a>]]></string>

in Java, replace body2 with:

String body2 = getString(R.string.readyandroid);

Then try passing it to the intent and sending it in an email, it should be a proper hyperlink as you would like it to be.

like image 60
Faraz Avatar answered Oct 21 '22 06:10

Faraz


What you do in body is perfectly correct.

But Gmail reads the extra android.intent.extra.TEXTas a string.

You are in fact making a feature request / reporting a bug.

like image 42
rds Avatar answered Oct 21 '22 07:10

rds