2011-06-08 79 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; 
     }