【问题标题】:Android: Using email intent to send email, possible to alter message just before sending?Android:使用电子邮件意图发送电子邮件,可以在发送之前更改消息吗?
【发布时间】:2011-09-10 13:32:28
【问题描述】:

我正在使用:

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

这让我可以为意图提供信息。

【问题讨论】:

    标签: android email android-intent message send


    【解决方案1】:

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

    如果电子邮件是使用任何其他应用程序(包括默认电子邮件应用程序)发送的,那么不,您将无法修改它。

    编辑

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

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

    【讨论】:

    • 您好,我知道您的意思,但我的意思是始终出现在消息末尾的页脚,例如“由 ABC iphone 客户端发布”,您在发布时看不到它但它附加在实际帖子中。
    • 这是能够修改任何东西的最后一刻。如果您不想这样,那么您必须在 JavaMail 中实现您的代码。有关详细信息,请参阅此问题:stackoverflow.com/questions/2020088/…
    【解决方案2】:
    @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;
            }
    

    【讨论】:

      【解决方案3】:

      你可以..

      1. 在您自己的应用程序中创建一个包含收件人、主题和文本文本编辑字段的表单。

      2. 将这些用户输入保存为字符串变量。

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-31
        • 1970-01-01
        • 1970-01-01
        • 2013-02-21
        • 2018-09-15
        • 1970-01-01
        • 2014-06-06
        相关资源
        最近更新 更多