发送电子邮件并附加工作簿|| Uri.parse()错误

时间:2018-10-26 13:47:21

标签: java android hssfworkbook

我正在开发一个应用程序,它将创建一个excel文件(工作簿),然后将其通过电子邮件发送给其他人。我已成功写入工作簿并将其保存到设备中,但是无法将其附加到电子邮件中。这是我设置的try&catch循环的结果:

10-26 14:33:30.775 30354-30354/com.example.joshua.eeltd W/FileUtils: Writing file/storage/emulated/0/Android/data/com.example.joshua.eeltd/files/ad3CableSupportContainmentCheckListform.xls
10-26 14:33:30.780 30354-30354/com.example.joshua.eeltd W/FileUtils: Failed to save fileandroid.os.FileUriExposedException: file://storage/emulated/0/Android/data/com.example.joshua.eeltd/files/ad3CableSupportContainmentCheckListform.xls exposed beyond app through ClipData.Item.getUri()

以下是我尝试将文件附加到电子邮件时使用的代码:

File file = new File(cx.getExternalFilesDir(null), form+".xls");
FileOutputStream os = null;
try {
    os = new FileOutputStream(file);
    wb.write(os);
    Log.w("FileUtils", "Writing file" + file);
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("application/excel");

    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {email});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,  cx.getString(R.string.subject));
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,  cx.getString(R.string.message));
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+  file));
    cx.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} catch (IOException e) {
    Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
    Log.w("FileUtils", "Failed to save file", e);
} finally {
    try {
        if (null != os)
            os.close();
        } catch (Exception ex) {
    }
}

如果您知道如何解决此错误,请告诉我,因为我不熟悉java / android studio中的该区域。非常感谢所有帮助,谢谢。

使用的变量: cx-活动上下文---- 电子邮件-用户的电子邮件--- 主题和消息只是字符串输入

0 个答案:

没有答案