I am attempting to use the email intent in Android Studio 3.01. If I use ACTION_SENDTO
, I get an error No apps can perform this action
even though the stock Android email client and the Gmail email app are both installed. If I use ACTION_SEND
in place of ACTION_SENDTO
, a screen is shown displaying every app on the device.
My goal is to invoke the default email client directly, without going through an intervening screen. What am I doing wrong?
The code I'm using is:
public void sendEmail(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Email sent!", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MapsActivityCurrentPlace.this,
"Email not installed.", Toast.LENGTH_SHORT).show();
}
}
EDITED
Thanks to the answer, final working code looks like:
public void sendEmail(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Message...");
try {
startActivity(emailIntent);
finish();
Log.i("Email sent!", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MapsActivityCurrentPlace.this,
"Email not installed.", Toast.LENGTH_SHORT).show();
}
}
}