Android – how do I make buttons submit multiple textviews to my email?

I checked. This is the most common way to send e-mail

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
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();
}

I'm confused about what this actually sends and how to do this when the user clicks the button. Do I put the recipient's email (me) like this?

 i.putExtra(Intent.EXTRA_EMAIL  , "myemail@gmail.com");

Then the subject of the email and the format of the message / body are the same?

Is this how I put the user's input into the email body? (user enters multiple EditText boxes)

 editText userTitle = (editText)findViewById(R.id.idOfTheEditText@R_915_2419@);
 editText userDescription = (editText)findViewById(R.id.idOfTheEditText@R_915_2419@);

And type it like this?

 i.putExtra(Intent.EXTRA_TEXT   , "userTitle", "userDescription");

Finally, what does it mean to have all toast and no email client installed? I'm new to Android application development. I'm making applications on Android studio! Thank you very much for all your help!! thank you!

resolvent:

The first is "toast"

Now the main part,

i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});

So in order to achieve this, you need to do the following things,

>Use an EditText to create a layout (where users can place e-mail addresses that can be passed to intent). Click a button to start intent. > now click the button to write this Code: –

public class MainActivity extends AppCompatActivity {
  EditText etRecipentId, etSubject, etBody;
  Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    etRecipentId = (EditText) findViewById(R.id.email_id);
    etSubject = (EditText) findViewById(R.id.et_subject);
    etBody = (EditText) findViewById(R.id.et_body);
  }

  b1.setOnClickListener(new OnClickListener() {
    public void onClick() {
      Intent i = new Intent(Intent.ACTION_SEND);
      i.setType("message/rfc822");
      i.putExtra(Intent.EXTRA_EMAIL, new String[] {
        etRecipentId.getText().toString();
      });
      i.putExtra(Intent.EXTRA_SUBJECT, etSubject.getText().toString(););
      i.putExtra(Intent.EXTRA_TEXT, etBody.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();
      }
    }
  });

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>