Android 調用系統Email發送帶多附件的郵件
眾所周知,在Android中調用其他程序進行相關處理,都是使用的Intent。當然,Email也不例外。
在Android中,調用Email有三種類型的Intent:
Intent.ACTION_SENDTO 無附件的發送
Intent.ACTION_SEND 帶附件的發送
Intent.ACTION_SEND_MULTIPLE 帶有多附件的發送
當然,所謂的調用Email,只是說Email可以接收Intent并做這些事情,可能也有其他的應用程序實現了相關功能,所以在執行的時候,會出現選擇框進行選擇。
1.使用SENTTO發送
Intent data=new Intent(Intent.ACTION_SENDTO); data.setData(Uri.parse("mailto:455245521@qq.com")); data.putExtra(Intent.EXTRA_SUBJECT, "這是標題"); data.putExtra(Intent.EXTRA_TEXT, "這是內容"); startActivity(data);
通過向Intent中putExtra來設定郵件的相關參數。
2.使用SEND發送
Intent intent = new Intent(Intent.ACTION_SEND); String[] tos = { "fdafdafa@gmail.com" }; String[] ccs = { "gegeff@gmail.com" }; String[] bccs = {"fdafda@gmail.com"}; intent.putExtra(Intent.EXTRA_EMAIL, tos); intent.putExtra(Intent.EXTRA_CC, ccs); intent.putExtra(Intent.EXTRA_BCC, bccs); intent.putExtra(Intent.EXTRA_TEXT, "body"); intent.putExtra(Intent.EXTRA_SUBJECT, "subject");intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Chrysanthemum.jpg")); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent);</pre><br />
很簡單,發送郵件中,有收件者,抄送者,密送者。 也就是分別通過
Intent.EXTRA_EMAIL,
Intent.EXTRA_CC,
Intent.EXTRA_BCC
來進行putExtra來設定的。
而單個附件的發送,則使用Intent.EXTRA_STREAM來設置附件的地址Uri。
3.使用SEND_MULTIPLE來進行多附件的發送
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); String[] tos = { "wingfourever@gmail.com" }; String[] ccs = { "tongyue@gmail.com" }; intent.putExtra(Intent.EXTRA_EMAIL, tos); intent.putExtra(Intent.EXTRA_CC, ccs); intent.putExtra(Intent.EXTRA_TEXT, "body"); intent.putExtra(Intent.EXTRA_SUBJECT, "subject");ArrayList<uri> imageUris = new ArrayList<uri>(); imageUris.add(Uri.parse("file:///sdcard/Chrysanthemum.jpg")); imageUris.add(Uri.parse("file:///sdcard/Desert.jpg")); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent);</uri></uri></pre><br />
發送多個附件,最主要的時候,通過putParcelableArrayListExtra將多個附件的Uri地址List設置進去就OK了。其實還是很簡單的。
如下是在三星galaxy tab 2 10.1上面的運行效果:
對于使用郵件發送,在很多的Android應用中都會使用到,跟微博分享一樣的常見。大家也只需要稍微了解下就可以了,畢竟還是很容易的。
轉載請注明出處:http://blog.csdn.net/ml3947/
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!