KyleM
KyleM

Reputation: 628

Add data from activity to email message body

I feel dumb for having to ask this but I cannot find how to take UI information from multiple EditText views and place in an email body. FYI I have the intent down, I just want to populate the message body.

    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[]{"[email protected]"});
            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();
            }

Upvotes: 0

Views: 828

Answers (2)

Niko
Niko

Reputation: 8153

Create a function which returns the whole String from all your text edits. For example:

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

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

    return text;
}

Use like:

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

Init member variables for class:

private EditText mEditText1;

Take all edit texts to member variables in onCreate after setContentView:

mEditText1 = (EditText) findViewById(R.layout.editText1);

Upvotes: 1

Krishna Suthar
Krishna Suthar

Reputation: 3075

Try this :

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
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();
}

Upvotes: 3

Related Questions