【问题标题】:Android open emailclient programmaticallyAndroid以编程方式打开电子邮件客户端
【发布时间】:2011-04-08 15:01:31
【问题描述】:

当我在我的应用程序中单击按钮时,是否可以打开电子邮件客户端(例如 gmail)?

【问题讨论】:

标签: android button gmail


【解决方案1】:

是的。您可以通过 Intents 启动它。

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));

【讨论】:

  • 工作伙伴。我就是这样做的 Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", EMAIL_ADDRESS, null));
【解决方案2】:
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", EMAIL_ADDRESS, null));

最新的做法

        i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
        i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
        startActivity(Intent.createChooser(i, "Send email"));

【讨论】:

  • 仅供参考,我认为Intent.createChooser(i, "Send email") 部分是不必要的。它使您可以自定义消息。对于标准选择器/选择器,您只需调用startActivity(i)
【解决方案3】:

如果上面的代码不起作用,那么试试这个。 经过测试和工作

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email"); 
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));

【讨论】:

    【解决方案4】:

    这对我来说很好用

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"mobiz@gmail.com"} );
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
                    startActivity(Intent.createChooser(shareIntent, "Share "));
    

    【讨论】:

      【解决方案5】:

      如果没有附件,您可以简单地使用以下代码:

      Intent i = new Intent(Intent.ACTION_SENDTO);
      i.setData(Uri.parse("mailto:support@mailname.com")); 
      i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
      startActivity(Intent.createChooser(emailIntent, "Send feedback"));
      

      有关详细信息,我建议您访问: https://developer.android.com/guide/components/intents-common.html#Email

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        • 2011-03-24
        • 2011-02-13
        相关资源
        最近更新 更多