11

我只想知道如何在 Android 中打开 Mail Composer。

对于 iOS,我会做这样的事情:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[controller setSubject:@"Mail subject"];
[controller setMessageBody:@"Mail body" isHTML:bool];
[controller setToRecipients:recipientsList];
if(controller) [self presentModalViewController:controller animated:YES];

安卓怎么样?

非常感谢。

4

4 回答 4

28
Intent intent=new Intent(Intent.ACTION_SEND);
String[] recipients={"xyz@gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT,"abc");
intent.putExtra(Intent.EXTRA_TEXT,"def");
intent.putExtra(Intent.EXTRA_CC,"ghi");
intent.setType("text/html");
startActivity(Intent.createChooser(intent, "Send mail"));
于 2012-07-11T08:40:53.737 回答
3

只能使用 ACTION_SENDTO 将应用列表限制为电子邮件应用。

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);
    }
}

请参阅https://developer.android.com/guide/components/intents-common.html#Email

于 2014-07-23T10:40:31.503 回答
2

如果您只想打开电子邮件客户端,则:

Intent intent = new Intent(Intent.ACTION_SEND);
String[] recipients = {"wantedEmail@gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, "emailTitle:");
intent.putExtra(Intent.EXTRA_CC, "ghi");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Send mail"));

大多类似于接受的答案,具有不同的 MIME 类型。

于 2015-04-22T03:02:16.123 回答
1

像这样:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] emailTo});
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[]{emailCC});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
    context.startActivity(Intent.createChooser(emailIntent, context.getString("send email using:")));

您可以在此处找到更多详细信息:http: //mobile.tutsplus.com/tutorials/android/android-email-intent/

于 2012-07-11T08:40:03.527 回答