Intent intent = new Intent();
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:chenkanzo@gmail.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "這裡是主旨。");
intent.putExtra(Intent.EXTRA_TEXT, "這是本文內容。");
startActivity(intent);
● 傳送附件(Send mail with enclosed file)
和傳送郵件不同的利用Intent.ACTION_SEND,
而附件檔案必須利用Uri型別指定。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
String[] to = {"hoge@example.com"};
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_SUBJECT, "這是主旨。");
intent.putExtra(Intent.EXTRA_TEXT, "這是本文內容。");
// 選擇一張圖片來加入附件
// 取得的SD卡資料夾
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "test.jpg");
intent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://"+ file.getAbsolutePath()));
intent.setType("image/jpeg");
//呼叫應用程式列表
startActivity(Intent.createChooser(intent,"請選擇郵件應用程式,例如GMAIL"));
延伸閱讀 Intent大全
沒有留言:
張貼留言