7

I have to format the text as table in the email body of email client. But i read somewhere android doesn't
support < table> tag. Is any other alternative is there for doing this? I tried a lot but still i am not finding any good solution. Please can anyone help me.

code

String body = "< table border="+"1"+">< tr>< td>row 1, cell 1< /td>"+ "< td>row 1, cell 2"+ "< /tr>"+ "< tr>"+ "< td>row 2, cell 1< /td>"+ "< td>row 2, cell 2< /td>"+ "< /tr>"+ "< /table>";

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body).toString());                    
startActivity(Intent.createChooser(emailIntent, "Email:"));

Actual Output is this

enter image description here

But I Expected output is similar to following:

enter image description here

naresh
  • 10,332
  • 25
  • 81
  • 124
  • duplicate from http://stackoverflow.com/questions/4350072/use-table-tag-in-android-email – njzk2 Aug 28 '12 at 07:47
  • 1
    @njzk2: it means Formatting the text as table is not possible in email client. No other alternative also. is it right? – naresh Aug 28 '12 at 07:51

1 Answers1

2

Try this:

How to send HTML email

Ok as the above isn't working try this:

http://www.edumobile.org/android/android-programming-tutorials/how-to-send-an-email/

The code from your example does work fine for anything without table. I thought it could be forced, but I've hit a wall here.

See: Sending html email in android using <table>, etc. - is there really no relatively built-in Intent way?

Perhaps this can work around it: Display HTML Table in webview

Or perhaps you can force something like this through in your activity (adjust to suit your purpose):

WebView webview = new WebView(this); setContentView(webview); String yourHtml = "<html><body><table>...</table></body></html>"; webview.loadData(yourHtml , "text/html", "utf-8"); 
Community
  • 1
  • 1
RossC
  • 1,200
  • 2
  • 11
  • 24
  • Ok, sorry about that, I haven't my SDK in work to try the code. I've edited my post linking you to a thread that should help resolve it, the solution given there does work. – RossC Aug 28 '12 at 07:52
  • Hi naresh, sorry these answers arent as clean cut as I would like. I'm trying to find a way to force this through as the tag appears to be unsupported in any way that might be useful for your needs.
    – RossC Aug 28 '12 at 08:24
  • then How to set the webview as body of the email client. – naresh Aug 28 '12 at 08:54
  • AFAIK you can't any other way. Those are the only work arounds I can locate. Otherwise you'll have to just manually draw it, or go lower level in the code and create something capable of parsing the field. Many of the Android email clients people use can't parse these tags upon receipt either (gmail can, but any stock one can't).
    – RossC Aug 28 '12 at 08:55
  • Alternatively you could detect the tag being used and save the HTML as an attachment to the email (use a webview or write it directly).
    – RossC Aug 28 '12 at 08:59
  • It means here only one option i.e., adding the attachment. rest all are not supported right? – naresh Aug 28 '12 at 09:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15882/discussion-between-naresh-and-rossc) – naresh Aug 28 '12 at 09:04
  • Finally the solution is it's better to add the html attachment to the email client. thanks for your help. If you have any idea about adding the html file as an attachment. – naresh Aug 28 '12 at 09:17