Android 系列 4 3使用附件傳送電子郵件

2021-07-25 21:49:00 字數 1598 閱讀 7954

4.3使用附件傳送電子郵件

問題您想要傳送附有附件的電子郵件。

解建立intent,新增擴充套件資料以指定要包括的檔案,並啟動乙個新活動以允許使用者傳送電子郵件。

討論傳送電子郵件的最簡單方法是建立乙個型別為action_send的intent:

intent intent = new intent(intent.action_send);

intent.putextra(intent.extra_subject,「測試單個附件」);

intent.putextra(intent.extra_email,new string );

intent.putextra(intent.extra_text,「帶附件的郵件」);

要附加單個檔案,我們向intent中新增一些擴充套件資料:

intent.putextra(intent.extra_stream,uri.fromfile(new file(「/ path / to / file」)));

intent.settype(「text / plain」);

mime型別始終可以設定為text / plain,但您可能需要更具體,以便解析您的郵件的應用程式可以正常工作。例如,如果你包括乙個jpeg影象,你應該寫影象/ jpeg。

要傳送包含多個附件的電子郵件,過程稍有不同,如示例4-5所示。

例項4-5。多個附件

intent intent = new intent(intent.action_send_multiple);

intent.settype("text/plain");

intent.putextra(intent.extra_subject, "test multiple attachments");

intent.putextra(intent.extra_text, "mail with multiple attachments");

intent.putextra(intent.extra_email, new string);

arraylisturis = new arraylist();

uris.add(uri.fromfile(new file("/path/to/first/file")));

uris.add(uri.fromfile(new file("/path/to/second/file")));

intent.putparcelablearraylistextra(intent.extra_stream, uris);

首先,您需要使用intent.action_send_multiple,它已從android 1.6開始提供。 第二,您需要建立乙個arraylist與您要附加到郵件的檔案的uri,並呼叫putparcelablearraylistextra。 如果您傳送不同型別的檔案,您可能想使用multipart / mixed作為mime型別。

最後,在這兩種情況下,都可以使用以下**啟動乙個新的activity:

startactivity(intent.createchooser(intent,「send mail」));

使用intent.createchooser是可選的,但它將允許使用者選擇他最喜歡的應用程式來傳送電子郵件。

python系列教程43

宣告 在人工智慧技術教學期間,不少學生向我提一些python相關的問題,所以為了讓同學們掌握更多擴充套件知識更好的理解人工智慧技術,我讓助理負責分享這套python系列教程,希望能幫到大家!由於這套python教程不是要由所寫,所以不如我的人工智慧技術教學風趣幽默,學起來比較枯燥 但它的知識點還是講...

Android通過Intent傳送帶附件的電子郵件

android.net.mailto類可以處理類似mailto android5858 163.com 這樣的電子郵件的url。那麼如果遇到乙個email的url我們又該如何解析內容呢?首先,我們看下mailto的公共方法 string getbody 從乙個url獲取郵件的正文內容 string ...

Android 系列 5 14使用捏合縮放

5.14使用捏合縮放 問題您想要使用觸控功能更改螢幕上檢視的影象的位置,並對放大和縮小操作使用收合和收合移動。解將影象縮放為矩陣以對其應用變換,以顯示不同的視覺效果。討論首先,在main.xml中的framelayout中新增乙個簡單的imageview,如下面的 所示 示例5 22將imagevi...