android - How to format the text as table in email

2019-01-12 06:56发布

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

1条回答
一纸荒年 Trace。
2楼-- · 2019-01-12 07:06

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"); 
查看更多
登录 后发表回答