将html table标记嵌入到电子邮件意图android中 [英] Embed html table tag in email intent android

查看:66
本文介绍了将html table标记嵌入到电子邮件意图android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个必须在邮件正文中嵌入 html表格标记的概念.我尝试了一些代码,使其在 2.2和2.3 操作系统中均能正常工作版本,但相同的代码在最新的操作系统版本(如4.0等)中不起作用.

I am working on a concept in which I have to embed html table tag in email body.I tried some work around code it's working fine in 2.2 and 2.3 OS versions but the same code is not working in latest OS versions like 4.0 etc.

我也尝试过Spannable and Html.fromHtml(),但它也无法正常工作.

I also tried Spannable and Html.fromHtml()but it's also not working.

这是我的代码,适用于2.2和2.3 OS版本:

Here is my code which is working on 2.2 and 2.3 OS versions:

//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 OS版本中都可以使用.

Also find the attached image which proves it worked in 2.2 and 2.3 OS versions.

推荐答案

尝试以下代码:-

final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
    .toString())
);

有关更多信息,请参见下面的链接:-

for more info see below link:-

android -如何在电子邮件客户端的电子邮件正文中将文本设置为表格格式

如何发送HTML电子邮件

http://blog. iangclifton.com/2010/05/17/sending-html-email-with-android-intent/

这篇关于将html table标记嵌入到电子邮件意图android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆