LoginSignup
10
5

More than 5 years have passed since last update.

AndroidのIntentでメールしか出てこないようにする

Last updated at Posted at 2017-11-04

ちょっとだけ詰まったのでメモ

調べていて多かったもの

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アプリしか選択画面に表示されなくなる。

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5