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:xyz@gmail.com"));
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[] = {"asd@gmail.com"};
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 关注
- 713 浏览
添加回答
举报