Sending HTML to the body of an email message

I am trying to send an email containing HTML, but HTML appears literally. How to send an HTML link? Here is my current code:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/html"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[EMAIL PROTECTED]"}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "<html><body>Example</body></html>"); context.startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
+4
source share
4 answers
 sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<a href=\"" + link_val + "\">" + text_value+ "</a>")); 
+5
source

There seems to be bugs in gmail and email apps on Android. The email application cannot send links correctly, if you put it in html, gmail sends the link in order. However, Gmail does not display the email with links, and the email application displays them correctly, so they are viewable. At least this is the case if you are using custom uri.

0
source

API 16 ++ has android.content.Intent.EXTRA_HTML_TEXT

0
source

You can use android.support.v4.content.IntentCompat.EXTRA_HTML_TEXT for APIs up to 16 years old. You should add this as an addition to the intention that you usually use. Also when specifying HTML text you need to add plain alternative text as well

So your code will look like

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/html"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[EMAIL PROTECTED]"}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); emailIntent.putExtra(android.support.v4.content.IntentCompat.EXTRA_HTML_TEXT, "<html><body>Example</body></html>"); context.startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
0
source

Source: https://habr.com/ru/post/1309651/


All Articles