In Android Studio choose New Project → Empty Views Activity, with Language Java and Minimum SDK API 24.
2. Build the form
Three Material text fields: To, Subject and a multi-line Message, plus a Send button.
3. Check the address
Patterns.EMAIL_ADDRESS checks the address looks right before opening anything.
4. Hand it to an email app
Create an Intent with ACTION_SENDTO and Uri.parse("mailto:"). Only email apps can handle mailto:, so chat apps don't appear. Add the address, subject and message as extras.
5. Let the user choose
Intent.createChooser lists every email app installed. If there are none, catch ActivityNotFoundException and show a message.
6. Run it
Fill in the form and tap Send: your email app opens with everything filled in.
Why use an Intent?
Your app never needs the user's email password or a mail server. The email app they already use does the sending.
What's improved over the video
Only email apps appear in the list, the address is checked, and phones with no email app get a clear message.
Files affected
Check what to add and what to replace before copying code.
Checks the address and hands the email to the phone's email app.
MainActivity.java
packagecom.example.emailintent;importandroid.content.ActivityNotFoundException;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.util.Patterns;importandroid.widget.Button;importandroid.widget.Toast;importandroidx.appcompat.app.AppCompatActivity;importcom.google.android.material.textfield.TextInputEditText;importcom.google.android.material.textfield.TextInputLayout;/**
* Writes an email and hands it to the phone's email app with an implicit Intent.
* The app never needs your email password: the email app does the sending.
*/publicclassMainActivityextendsAppCompatActivity{@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);Screens.setUp(this,R.layout.activity_main);TextInputLayout toLayout =findViewById(R.id.toLayout);TextInputEditTextto=findViewById(R.id.to);TextInputEditText subject =findViewById(R.id.subject);TextInputEditText message =findViewById(R.id.message);Button send =findViewById(R.id.btnSend);
send.setOnClickListener(v ->{String address =String.valueOf(to.getText()).trim();if(!Patterns.EMAIL_ADDRESS.matcher(address).matches()){
toLayout.setError(getString(R.string.error_email));return;}
toLayout.setError(null);// ACTION_SENDTO with a mailto: address opens only email apps, not every sharing app.Intent email =newIntent(Intent.ACTION_SENDTO,Uri.parse("mailto:")).putExtra(Intent.EXTRA_EMAIL,newString[]{address}).putExtra(Intent.EXTRA_SUBJECT,String.valueOf(subject.getText())).putExtra(Intent.EXTRA_TEXT,String.valueOf(message.getText()));try{startActivity(Intent.createChooser(email,getString(R.string.choose_app)));}catch(ActivityNotFoundException e){Toast.makeText(this,R.string.no_email_app,Toast.LENGTH_LONG).show();}});}}