在电子邮件中备份时在电子邮件中制作表格

时间:2017-12-19 13:04:36

标签: android

我制作了一款需要在电子邮件中备份数据的应用。我正在寻找是否可以在电子邮件中创建一个表,而不是动态地将数据放到它上面。这可能吗?

 public void sendEmail(){
    Intent emailIntent=new Intent(Intent.ACTION_SEND);

    emailIntent.setType("text/html");
    emailIntent.putExtra(Intent.EXTRA_EMAIL,email_global);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Backup of date:"+date_global+"  Session:"+session_global);
    Toast.makeText(this,getResult(),Toast.LENGTH_LONG).show();
    emailIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(getResult()));


    try{
        startActivity(Intent.createChooser(emailIntent,"Send Mail..."));
        finish();
    }catch(Exception e){
        Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show();
    }

}

   public String getResult(){
    String result="<html><body><table border=\"1\"><tr><th>vendor_id</th><th>type</th><th>amount</th><th>remarks</th>"+"</tr>";
    db=dbhandler.getDb();

    try {
        String query = "SELECT * FROM vendor_transaction where session='"+session_global+"'";
        Cursor c = db.rawQuery(query, null);
        c.moveToFirst();
        while (!c.isAfterLast()) {
            int vendor_id=c.getInt(c.getColumnIndex("vendor_id"));
            int type=c.getInt(c.getColumnIndex("type"));
            String amount=c.getString(c.getColumnIndex("amount"));
            String remarks=c.getString(c.getColumnIndex("remarks"));
            result+="<tr><td>"+vendor_id+"</td><td>"+type+"</td><td>"+amount+"</td><td>"+remarks+"</td></tr>";
            c.moveToNext();
        }
        result+="</table></body></html>";
    }catch(Exception e){

    }
    return result;

}

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须使用此代码发送

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, the_body);

startActivity(Intent.createChooser(intent, "Send Email"));

您可以通过一个漂亮的模板创建一个默认的邮件布局,并创建一个包含{{enter_data_here}}等文本字段的表格布局,并将它们放在字符串变量中。通过String.replace("{{enter_data_here}}",data);制作循环并填充数据。我不擅长HTML,所以不能用它来指导你。您可以在网上找到更多代码。