【问题标题】:how to share a File object by email?如何通过电子邮件共享文件对象?
【发布时间】:2018-07-04 22:06:01
【问题描述】:
我以编程方式创建一个文件对象。我想知道如何在不保存在设备上的情况下直接通过电子邮件分享。
我想要一个这样的方法:
private void sendFileByEmail(File aFile, String emailTitle)
{
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, emailTitle);
// and then ???...
}
感谢您的帮助!
【问题讨论】:
标签:
java
android
file
email
android-intent
【解决方案1】:
这可能是和选项
private void sendFileByEmail(File aFile, String emailTitle)
{
Uri path = Uri.fromFile(afile);
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..."));
}