将活动中的数据添加到电子邮件正文中

时间:2012-05-07 04:27:54

标签: android string email

我不得不问这个问题,但是我找不到如何从多个EditText视图中获取UI信息并将其放在电子邮件正文中。仅供参考我有意图,我只想填充信息正文。

    Intent buildingfireemail = new Intent(android.content.Intent.ACTION_SEND);
            buildingfireemail.setType("plain/text");///.setType("message/rfc822")
            buildingfireemail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
            buildingfireemail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
            buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, "Text"
    //////////////I need to add data from 80+ views into here.
    );try {
                startActivity(Intent.createChooser(buildingfireemail, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(BuildingFireActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }

2 个答案:

答案 0 :(得分:2)

试试这个:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , editText.getText().toString());
try 
{
     startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}

答案 1 :(得分:1)

创建一个函数,从所有文本编辑中返回整个String。例如:

private String getText() {
    String text = "";

    text += mEditText1.getText().toString() + "\n";
    text += mEditText2.getText().toString() + "\n";

    return text;
}

使用类似:

buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, getText());

类的Init成员变量:

private EditText mEditText1;

在setContentView:

之后,将所有编辑文本转换为onCreate中的成员变量
mEditText1 = (EditText) findViewById(R.layout.editText1);