【问题标题】:Android : how to open a mail composer view?Android:如何打开邮件编辑器视图?
【发布时间】:2012-07-11 08:37:53
【问题描述】:

我只是想知道如何在 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 email gmail mfmailcomposer


【解决方案1】:
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"));

【讨论】:

  • 我会尽快做的。我只是有一个小问题:如果我这样做intent.putExtra(Intent.EXTRA_TEXT, "<html>Hello<br/>Just a little mail.</html>"); intent.setType("text/html");,在邮件编写器中,文本不是 html 格式的。我试过Intent.EXTRA_HTML_TEXT,但它让我的应用停止运行。
  • 编辑:最后我得到了它与intent.setType("text/html"); intent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<html>Hello<br/><b>Just a little test.</b></html>"));的合作。再次感谢您。
【解决方案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

【讨论】:

    【解决方案3】:

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

    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 类型不同。

    【讨论】:

      【解决方案4】:

      像这样:

      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/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多