2

I am working on ArrayList, i want to send email type of html format with arraylist content, i am trying to write array content in BufferedWriter Like..

mOrderList = db.getOrderList();
    // getting all arrayList content
     for (int i = 0; i < mOrderList.size(); i++) {
     no = mOrderList.get(i).getId();
     itemName = mOrderList.get(i).getOrderItemName();
     unit = mOrderList.get(i).getOrderUnit();
     qty = mOrderList.get(i).getOrderQTY();
     rate = mOrderList.get(i).getOrderRate();
     amt = mOrderList.get(i).getOrderAmount();
     try {
         mbufferWriter =new BufferedWriter(new FileWriter("/data/data/com.sample.category/abc.txt"));
     mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body> <table>"
                + "<tr><th>Item No</th>" + "<th>Item Name</th>"
                + "<th>Unit</th>" + "<th>QTY</th>" + "<th>Item Rate</th>"
                + "<th>Amount</th></tr>");
     mbufferWriter.append("<tr><td>" +no+"</td>");
     mbufferWriter.append("<td>"+itemName+ "<td>");
     mbufferWriter.append("<td>"+unit+ "<td>");
     mbufferWriter.append("<td>"+qty+ "<td>");
     mbufferWriter.append("<td>"+rate+ "<td>");
     mbufferWriter.append("<td>"+amt+ "<td></tr>");
     mbufferWriter.append("</body></table></html>");
     mbufferWriter.close();

     } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

     }//for

and trying to send an email like this but it gives error...

Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { "abc@gmail.com" });
                i.putExtra(Intent.EXTRA_SUBJECT, "sample email sending");

                i.putExtra(Intent.EXTRA_TEXT,Html.toHtml((Spanned) mbufferWriter));

                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                    // startActivity(i);
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(EmailActivity.this,
                            "There are no email clients installed.",
                            Toast.LENGTH_SHORT).show();
                }

can any one help me fix this problem .. Thanks in advance..

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
CrazyMind
  • 1,006
  • 1
  • 20
  • 22

2 Answers2

0

Html.toHtml doesn't support <table>. It only supports basic tags like <b><u><i>...

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Sébastien REMY
  • 2,399
  • 21
  • 39
-1

Use a pre tag to create a table:

 mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body>" + 
        "<pre> " +
            "  Item No    Item Name    Unit     QTY   Item Rate     Amount" +
        "</pre>");
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265