ちょっとだけ詰まったのでメモ
調べていて多かったもの
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();
}
ソース: https://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application
ただ、これだとLINEやSlackなどが選択肢に出てしまって、自分が求めているメールを送るという目的に沿わない。
改善策
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
ソース: https://stackoverflow.com/questions/8701634/send-email-intent
これをやるとGmailなどの、mailアプリしか選択画面に表示されなくなる。