android 發送帶附件的郵件
// 附件文件地址
String fileName = items.get(arg2).get(NAME);
File file = new File(Environment.getExternalStorageDirectory(), fileName);
// 啓動系統郵件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("subject", file.getName());
// 正文
intent.putExtra("body", fileName);
// 添加附件,附件爲file對象
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
// 如果是gz使用gzip的mime
if (file.getName().endsWith(".gz")) {
intent.setType("application/x-gzip");
}
// 純文本則用text/plain的mime
else if (file.getName().endsWith(".txt")) {
intent.setType("text/plain");
}
// 其他的均使用流當做二進制數據來發送
else {
intent.setType("application/octet-stream");
}
// 調用系統的mail客戶端進行發送。
startActivity(intent);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.