【问题标题】: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..."));
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      相关资源
      最近更新 更多