0

I have an activity, which has two TextFields, where the user can input some text.

There is a button below them, which I want to submit the information input the two TextFields. Either as an email or a message.

Is there a way where the activity is basically submitting the user info to me?

1
  • You basically need an Intent with EXTRA_EMAIL, EXTRA_SUBJECT, EXTRA_TEXT extras. Commented Oct 11, 2015 at 11:23

2 Answers 2

1

You need to use an Intent to open "Compose new email" with required data filled in.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{emailAddressEditText.getText().toString()});
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubjectEditText.getText().toString());
intent.putExtra(Intent.EXTRA_TEXT   , emailBodyEditText.getText().toString());
try {
    startActivity(Intent.createChooser(intent, "Leave feedback..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "No email clients installed.", Toast.LENGTH_SHORT).show();
}
Sign up to request clarification or add additional context in comments.

Comments

0

1.Use Intent

2.Use .setType("message/rfc822")

buttonSend = (Button) findViewById(R.id.buttonSend);
textTo = (EditText) findViewById(R.id.editTextTo);
 textSubject = (EditText) findViewById(R.id.editTextSubject);
 textMessage = (EditText) findViewById(R.id.editTextMessage);

 buttonSend.setOnClickListener(new OnClickListener() {

 @Override
 public void onClick(View v) {

 String to = textTo.getText().toString();
 String subject = textSubject.getText().toString();
 String message = textMessage.getText().toString();

     Intent email = new Intent(Intent.ACTION_SEND);
     email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
     email.putExtra(Intent.EXTRA_SUBJECT, subject);
     email.putExtra(Intent.EXTRA_TEXT, message);

     email.setType("message/rfc822");

 startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.