Android:使用电子邮件意图发送电子邮件,可能在发送之前更改邮件?

时间:2011-06-08 03:39:33

标签: android email android-intent message send

我正在使用:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

要发送电子邮件,我需要在邮件中添加一些页脚,是否有任何监听器或某种方式可以在用户点击“发送”时编辑邮件?

谢谢!

编辑:

下面是我使用的代码:

private void sendEmail(String recipient, String subject, String message) {
    try {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        if (recipient != null)  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
        if (subject != null)    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    } catch (ActivityNotFoundException e) {
        // cannot send email for some reason
    }
}

没有类似的字段:

android.content.Intent.EXTRA_EMAIL

让我可以提供意图信息。

3 个答案:

答案 0 :(得分:2)

如果电子邮件是从您自己的应用发送的,那么您需要在触发意图之前添加页脚

如果使用任何其他应用程序(包括默认电子邮件应用程序)发送电子邮件,则不会,您将无法对其进行修改。

编辑

在上面的情况中,您只需要在行之前的任何时间将签名附加到message字符串

if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);

答案 1 :(得分:1)

@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("mailto:")) { 
                try {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
                    emailIntent.setType("message/rfc822");
                    String recipient = url.substring( url.indexOf(":")+1 );
                    if (TextUtils.isEmpty(recipient)) recipient = "loco@wareninja.com";
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mContext.getString(R.string.email_subject));
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mContext.getString(R.string.email_message, " "));

                    mContext.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                }
                catch (Exception ex) {}
            }
            return true;
        }

答案 2 :(得分:0)

你可以......

  1. 使用“收件人”,“主题”和“文本”TextEdit字段在您自己的应用中创建表单。

  2. 将这些用户输入保存为String变量。

  3. 追加/编辑字符串变量

  4. 将最终变量传递到您的emailIntent.putExtra()

  5. 然后,您的用户可以决定他们是否喜欢这些更改,只需按发送即可。