androidemail
① Android開發中怎樣調用系統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:[email protected]")); data.putExtra(Intent.EXTRA_SUBJECT, "這是標題"); data.putExtra(Intent.EXTRA_TEXT, "這是內容"); startActivity(data); Intent data=new Intent(Intent.ACTION_SENDTO); data.setData(Uri.parse("mailto:[email protected]")); 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 = { "[email protected]" }; String[] ccs = { "[email protected]" }; String[] bccs = {"[email protected]"}; 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:///mnt/sdcard/a.jpg")); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent); Intent intent = new Intent(Intent.ACTION_SEND); String[] tos = { "[email protected]" }; String[] ccs = { "[email protected]" }; String[] bccs = {"[email protected]"}; 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:///mnt/sdcard/a.jpg")); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent);
很簡單,發送郵件中,有收件者,抄送者,密送者。 也就是分別通過 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 = { "[email protected]" }; String[] ccs = { "[email protected]" }; 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:///mnt/sdcard/a.jpg")); imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg")); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); String[] tos = { "[email protected]" }; String[] ccs = { "[email protected]" }; 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:///mnt/sdcard/a.jpg")); imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg")); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); intent.setType("image/*"); intent.setType("message/rfc882"); Intent.createChooser(intent, "Choose Email Client"); startActivity(intent);
發送多個附件,最主要的時候,通過putParcelableArrayListExtra將多個附件的Uri地址List設置進去就OK了。其實還是很簡單的。
② Android開發中怎樣調用系統Email發送郵件
在Android中,調用Email有三種類型的Intent:
Intent.ACTION_SENDTO 無附件的發送
Intent.ACTION_SEND 帶附件的發送
Intent.ACTION_SEND_MULTIPLE 帶有多附件的發送
【方法1】使用SENTTO發送
java">Intentdata=newIntent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:[email protected]"));
data.putExtra(Intent.EXTRA_SUBJECT,"這是標題");
data.putExtra(Intent.EXTRA_TEXT,"這是內容");
startActivity(data);
Intentdata=newIntent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:[email protected]"));
data.putExtra(Intent.EXTRA_SUBJECT,"這是標題");
data.putExtra(Intent.EXTRA_TEXT,"這是內容");
startActivity(data);
【方法2】使用SEND發送
Intentintent=newIntent(Intent.ACTION_SEND);
String[]tos={"[email protected]"};
String[]ccs={"[email protected]"};
String[]bccs={"[email protected]"};
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:///mnt/sdcard/a.jpg"));
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent,"ChooseEmailClient");
startActivity(intent);
Intentintent=newIntent(Intent.ACTION_SEND);
String[]tos={"[email protected]"};
String[]ccs={"[email protected]"};
String[]bccs={"[email protected]"};
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:///mnt/sdcard/a.jpg"));
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent,"ChooseEmailClient");
startActivity(intent);
很簡單,發送郵件中,有收件者,抄送者,密送者。 也就是分別通過
Intent.EXTRA_EMAIL,
Intent.EXTRA_CC,
Intent.EXTRA_BCC
來進行putExtra來設定的,而單個附件的發送,則使用Intent.EXTRA_STREAM來設置附件的地址Uri。
【方法3】使用SEND_MULTIPLE來進行多附件的發送
Intentintent=newIntent(Intent.ACTION_SEND_MULTIPLE);
String[]tos={"[email protected]"};
String[]ccs={"[email protected]"};
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=newArrayList<uri>();
imageUris.add(Uri.parse("file:///mnt/sdcard/a.jpg"));
imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg"));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent,"ChooseEmailClient");
startActivity(intent);
Intentintent=newIntent(Intent.ACTION_SEND_MULTIPLE);
String[]tos={"[email protected]"};
String[]ccs={"[email protected]"};
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=newArrayList<uri>();
imageUris.add(Uri.parse("file:///mnt/sdcard/a.jpg"));
imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg"));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent,"ChooseEmailClient");
startActivity(intent);
③ 如何設置Android系統電子郵件客戶端
第一步:點擊【設置】,進入【添加帳戶】-->【電子郵件】打開設置電子郵件界面;