Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

android - How to format the text as table in email body of email client

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...