2011-06-08 85 views
3

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

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 

这让我提供信息的意图。

回答

2

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

如果使用任何其他应用程序(包括默认电子邮件应用程序)发送电子邮件,则不会修改它。

编辑

在上述情况下,你只需要签名追加到message弦,任何时候前行

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

请看我更新的代码,谢谢! – hzxu 2011-06-08 05:00:45

+0

@hzxu见上面 – Aleadam 2011-06-08 05:08:48

+0

嗨,我知道你的意思,但我的意思是总是出现在信息的末尾,例如“由ABC iphone客户端发布”的页脚,当你发布时你看不到它,但它附加在实际的文章中。 – hzxu 2011-06-08 05:13:27

0

你可以..

  1. 在To,Subject,和TextEdit字段的自己的应用程序中创建一个表单。

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

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

  4. 传递完成变量到您的emailIntent.putExtra()的

然后,如果他们喜欢的变更或不是你的用户就可以决定的,和只需按下发送。

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 = "[email protected]"; 
        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; 
     }