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?

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
Rohan Paul
  • 11
  • 4

2 Answers2

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();
}
Ivan V
  • 3,024
  • 4
  • 26
  • 36
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 :"));
}
});
tk1505
  • 312
  • 1
  • 9