Using Android Intent.ACTION_SEND for sending email

前端 未结 17 1276
野趣味
野趣味 2020-11-29 23:07

I\'m using Intent.ACTION_SEND to send an email. However, when I call the intent it is showing choices to send a message, send an email, and also to

17条回答
  •  再見小時候
    2020-11-29 23:30

    I notice, that this is an pretty old question but it is the first result when searching for a "Send mail" solution and all answers have a common problem:

    Using Intent.ACTION_SEND and intent.setType("message/rfc822") will result in a chooser that not only shows mail apps but all apps that can handle any MIME type support by message/rfc822, e.g. .mhtml, .mht, .mime. Beside mail apps this could be Google Drive, Dropbox, Evernote, etc.

    The only solution I found to limit the chooser to mail apps only is to use Intent.ACTION_SENDTO instead:

    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","address@example.com", null));
    intent.putExtra(Intent.EXTRA_SUBJECT, "My Mail");
    intent.putExtra(Intent.EXTRA_TEXT   , "My Message");
    
    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
    

提交回复
热议问题