Email issue (send hyperlink in email body) android

13,815

Solution 1

Try this one.. It is working for me..

String link_val = "www.google.com"
String body = "<a href=\"" + link_val + "\">" + link_val+ "</a>"

intent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));

Solution 2

If you make the EXTRA_TEXT a full html document by enclosing the source text in <html><body> and <\body><\html> it will work properly with GMail, that is, you can have a proper description for the link.

Unfortunately, it won't work with all email apps. For example it does not work with the Samsung email app on my Galaxy S3. My conclusion is that you cannot safely do this, which is very annoying.

Solution 3

CapDroid's answer does not look like it solves the problem, as per scottytab's comment.

Try;

yourIntent.setType("text/html");
yourIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));

If that doesn't work try adding;

yourIntent.putExtra(android.content.Intent.EXTRA_HTML_TEXT, Html.fromHtml(body));

References; fromHtml, EXTRA_HTML_TEXT

Share:
13,815

Related videos on Youtube

J.D.
Author by

J.D.

Updated on October 01, 2022

Comments

  • J.D.
    J.D. over 1 year
    mIntent = new Intent(Intent.ACTION_SEND);
    mIntent.putExtra(Intent.EXTRA_SUBJECT, getString(""));
    
    mIntent.setType("text/html");  
    Uri myUri = Uri.parse("http://www.Google.com/");
    mIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml("<a href=\""+myUri+"\">Link</a>"));
    startActivity(android.content.Intent.createChooser(mIntent, "Email:"));
    

    I tried the above code but at receiver side I can not get Link. it convert into normal text..

  • Mohammed Azharuddin Shaikh
    Mohammed Azharuddin Shaikh over 11 years
    The difference is that if we provide link and its value to the same then it is working else not i.e. <a href=\"www.example.com\">www.example.com</a> is working while <a href=\"www.example.com\">my custom text</a> isn't.
  • Petr Prazak
    Petr Prazak over 11 years
    I'm seeing the same behaviour, I'm guessing <a href=\"www.example.com\">www.example.com</a> is working because gmail auto converts text that starts http or www into a link.
  • Mr.G
    Mr.G over 7 years
    This works prefectly fine only when we put www . but is there any way that can i put some other text to link_val ex-: this
  • Niranj Patel
    Niranj Patel over 7 years
    @Mr.G no, Android not supporting this way.
  • Mr.G
    Mr.G over 7 years
    But this has worked on previous gmail versions . Not works with the update version . Lets say for marshmellow
  • Galya
    Galya almost 7 years
    yourIntent.setType("text/html") leads to "No application to perform this action" on Marshmallow and yourIntent.putExtra(android.content.Intent.EXTRA_HTML_TEXT, Html.fromHtml(body)); doesn't make any difference
  • Jiechao Wang
    Jiechao Wang over 6 years
    should be </body></html> at the end