我正在研究一个概念,其中我必须在电子邮件正文中嵌入html表格标签。我尝试了一些解决代码的方法,它在2.2和2.3操作系统中工作正常版本,但相同的代码在最新的操作系统版本(如 4.0 等)中不起作用。
我还尝试了Spannable和Html.fromHtml()
但它也不起作用。
这是我的代码,适用于 2.2 和 2.3 操作系统版本:
//SEND EMAIL
private void sendEmail(String imageUri) throws WriterException{
//....................Prepare share email data.............................
int itemNumber=0;
titleBuffer=new StringBuffer();
titleBuffer.append("<html><body><table border="+"1"+"><tr border="+"0"+"><th>Item number</th>"+
"<th>Barcode</th>"+"<th>Product name</th>"+"<th>Quantity</th></tr>");
for(int i=0;i<_productList.size();i++){
itemNumber=i+1;
titleBuffer.append("<tr border="+"0"+"><td>"+itemNumber+"</td>"+
"<td>"+_productList.get(i).getProductBarcode()+"</td>"+"<td>"+_productList.get(i).getProductName()+"</td>"+
"<td>"+_productList.get(i).getProductQuantity()+"</td></tr>");
/*titleBuffer.append("<tr border="+"0"+"><td>"+itemNumber+"</td>"+
"<td>"+_productList.get(i).getProductBarcode()+"</td>"+"<td>"+_productList.get(i).getProductName()+"</td>"+
"<td>"+_productList.get(i).getProductQuantity()+"</td>"+"<td>"+
"<img src="+"/'data:image/png;base64, "+generateBarcodeImage(GenerateBarcode.encodeAsBitmap(_productList.get(i).getProductBarcode(),
BarcodeFormat.CODE_128, 600, 300))+"/'/></td></tr>");*/
}
titleBuffer.append("</table></body></html>");
SpannedString bar = new SpannedString(titleBuffer.toString());
if(_productList.size()==0){
titleBuffer.append("NA");
}
//..........................................................................
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Shopping List");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,titleBuffer.toString());
emailIntent.putExtra(Intent.EXTRA_STREAM, emailImageUri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
还可以找到所附图像,证明它可以在 2.2 和 2.3 操作系统版本中运行。
最佳答案
这取决于处理它的电子邮件客户端。并非所有电子邮件客户端都支持所有 HTML 标记。至少 Gmail 不支持。它仅适用于基本标签,例如 <b>
, <i>
等等,它不适用于特别是 <img>
标签。
请参阅这些帖子以获取更多信息,
Android, How to send HTML email and force Android to send it through G-Mail not other applications?
How to send html content with image through android default email client?
关于android - 在电子邮件 Intent android中嵌入html表格标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23774094/