Android:如何打开邮件作曲家视图?

时间:2012-07-11 08:37:53

标签: android email gmail mfmailcomposer

我只是想知道如何在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];

Android怎么样?

非常感谢。

4 个答案:

答案 0 :(得分:26)

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

答案 1 :(得分:2)

只有使用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

答案 2 :(得分: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类型。

答案 3 :(得分: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/