3 回答
TA貢獻1777條經驗 獲得超3個贊
Folder_name是手機內部存儲器中文件的名稱。(實際上是EXTERNAL_STORAGE)。file_name是您要發送的文件的名稱。
private void ShareViaEmail(String folder_name, String file_name) {
try {
File root= Environment.getExternalStorageDirectory();
String filelocation= root.getAbsolutePath() + folder_name + "/" + file_name;
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
String message="File to be shared is " + file_name + ".";
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setData(Uri.parse("mailto:[email protected]"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch(Exception e) {
System.out.println("is exception raises during sending mail"+e);
}
}
TA貢獻1802條經驗 獲得超5個贊
使用以下代碼在電子郵件中發送文件。
String filename="contacts_sid.vcf";
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);
Uri path = Uri.fromFile(filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"[email protected]"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
- 3 回答
- 0 關注
- 745 瀏覽
添加回答
舉報
