android - 在电子邮件 Intent android中嵌入html表格标签

标签 android html-email

我正在研究一个概念,其中我必须在电子邮件正文中嵌入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 操作系统版本中运行。

enter image description here

最佳答案

这取决于处理它的电子邮件客户端。并非所有电子邮件客户端都支持所有 HTML 标记。至少 Gmail 不支持。它仅适用于基本标签,例如 <b> , <i>等等,它不适用于特别是 <img>标签。

请参阅这些帖子以获取更多信息,

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

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/

相关文章:

java - onBack按回到主屏幕

html - 是否可以在响应式 HTML 电子邮件中将按钮固定在行的底部?

android - 应用程序在重启时总是忘记共享首选项

java - 分析心率监测器返回的数据

android - Kotlin - 在 android 中使用 Realm 模块

python - 我如何将电子邮件解析为有意义的内容(尤其是文本/html 部分)? - python /pop3

email - 如何从本地 asp.net 4.0 Web 应用程序发送启用图像的电子邮件

Android 安全 JSON 响应

html - Magento 1.9 交易电子邮件变量编辑

css - HTML 电子邮件中的字体颜色 - Gmail