-1

I am currently writing an app with a simple form that when you click submit, an e-mail is opened and the data entered into the textviews is automatically populated into the message body.

protected void sendEmail() {

            EditText nameField = (EditText) findViewById(R.id.nameField);
            String nameValue = nameField.getText().toString();

            EditText dateField = (EditText) findViewById(R.id.dateField);
            String dateValue = dateField.getText().toString();

            EditText ahsField = (EditText) findViewById(R.id.ahsField);
            String ahsValue = ahsField.getText().toString();


            Log.i("Send email", "");
            String[] TO = {""};
            Intent emailIntent = new Intent(Intent.ACTION_SEND);

            emailIntent.setData(Uri.parse("mailto:"));
            emailIntent.setType("text/plain");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject...");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "MESSAGE BODY HERE?");

            try {

                startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                finish();
                Log.i("Finished sending email", "");
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(DDActivity.this, "There is no email client installed", Toast.LENGTH_SHORT).show();
            }

        }

This is what i have so far, any help would be greatly appreciated!

Cœur
  • 37,241
  • 25
  • 195
  • 267
DanielPetters386
  • 133
  • 1
  • 1
  • 6

1 Answers1

0

The following code works just tried it

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"foo@bar.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
  startActivity(Intent.createChooser(i, "Choose email...");
} catch (android.content.ActivityNotFoundException ex) {
    // handle edge case where no email client is installed
}
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74