如何修复android.os.FileUriExposedException:file:///storage/emulated/0/Documents/SM.pdf通过Intent.getData()在应用程序之外公开

时间:2019-06-25 06:57:03

标签: java android

这是我的代码:

private void createPdf() {

    File docsFolder = new File(Environment.getExternalStorageDirectory() + "/Documents");
    File pdfFile = new File(docsFolder.getAbsolutePath(), "SM.pdf");
    try {
        OutputStream output = new FileOutputStream(pdfFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        document.writeTo(new FileOutputStream(pdfFile));enter code here
    } catch (IOException e) {
        e.printStackTrace();
    }
    // close the document
    document.close();
    Toast.makeText(this, "PDF is created!!!", Toast.LENGTH_SHORT).show()
   // openGeneratedPDF();
}

注销:

  

android.os.FileUriExposedException:file:///storage/emulated/0/Documents/SM.pdf通过Intent.getData()在应用程序之外公开

1 个答案:

答案 0 :(得分:0)

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 

StrictMode.setVmPolicy(builder.build());