Send Email Intent

前端 未结 30 3288
忘掉有多难
忘掉有多难 2020-11-22 07:27
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(\"text/html\");
intent.putExtra(Intent.EXTRA_EMAIL, \"emailaddress@emailaddress.com\");
intent.putExtr         


        
相关标签:
30条回答
  • 2020-11-22 08:06

    This is quoted from Android official doc, I've tested it on Android 4.4, and works perfectly. See more examples at https://developer.android.com/guide/components/intents-common.html#Email

    public void composeEmail(String[] addresses, String subject) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
    
    0 讨论(0)
  • 2020-11-22 08:06

    Maybe you should try this: intent.setType("plain/text");

    I found it here. I've used it in my app and it shows only E-Mail and Gmail options.

    0 讨论(0)
  • 2020-11-22 08:07

    The following code works for me fine.

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc@gmailcom"});
    Intent mailer = Intent.createChooser(intent, null);
    startActivity(mailer);
    
    0 讨论(0)
  • 2020-11-22 08:08

    If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:

    public void composeEmail(String[] addresses, String subject) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
    

    I found this in https://developer.android.com/guide/components/intents-common.html#Email

    0 讨论(0)
  • Finally come up with best way to do

    String to = "test@gmail.com";
    String subject= "Hi I am subject";
    String body="Hi I am test body";
    String mailTo = "mailto:" + to +
            "?&subject=" + Uri.encode(subject) +
            "&body=" + Uri.encode(body);
    Intent emailIntent = new Intent(Intent.ACTION_VIEW);
    emailIntent.setData(Uri.parse(mailTo));
    startActivity(emailIntent);
    
    0 讨论(0)
  • 2020-11-22 08:13

    This works for me perfectly fine:

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("mailto:" + address));
        startActivity(Intent.createChooser(intent, "E-mail"));
    
    0 讨论(0)
提交回复
热议问题