Valentin
Valentin

Reputation: 5608

HTML links disappear from Intent-generated email (Android 4.1+)

I'm facing a problem happening on Android 4.1+ devices. I want to send an email (via Intent) containing html links. I know this works on android 2.x devices because I did this for months.

Here is the java code:

startActivity(Intent.createChooser(
new Intent(Intent.ACTION_SEND)            
.putExtra(Intent.EXTRA_SUBJECT, "A subject")  
.setType("text/html")
.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("Some text ... <a href="http://www.weburl.com">Some text</a>)), "Email"));

On Android 4.1: When I use this code, Gmail show the text as expected AND I SEE THE LINKS in blue an underlined. But I receive this mail without the links.

On Android 2.x: All is perfect. I receive the email with the links

Can somebody help me to resolve this problem?

Upvotes: 4

Views: 2388

Answers (1)

Stephan Celis
Stephan Celis

Reputation: 2622

I think that the email applications don't have full html support. I have the following code:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","", null))            
                .putExtra(Intent.EXTRA_SUBJECT, "LIJSTJE fb")  
                .putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
                 .append("<p style='font-weight:bold;'>Some Content</p>")
                 .append("<a>http://www.google.com</a><br/>")
                 .append("<a href='http://www.facebook.com'>facebook</a>")
                 .append("<small><p>More content</p></small>")
                 .toString()));

                startActivity(Intent.createChooser(emailIntent, "Send email..."));

The paragraphs and new lines are added as expected. The styling however isn't. Also when you print the full url you get a link, but when you do it like the facebook link, you don't.

I suspect that the email client on the phone removes styling and makes sure that links link to the visible text. So the user knows where the link goes to. Also if you think about it the native gmail app doesn't have styling options. So this may cause the remove styling behaviour.

At least that's my theory. :)

(NOTE: I only tested on the native gmail application!)

Also I changed Intent type from SEND to SENDTO this way it only uses email clients and not other applications. And I removed the setType() method, because when you use it, you get an "application not found" error.

Upvotes: 4

Related Questions