【问题标题】:How to fix android.os.FileUriExposedException: file:///storage/emulated/0/Documents/SM.pdf exposed beyond app through Intent.getData()如何修复 android.os.FileUriExposedException:file:///storage/emulated/0/Documents/SM.pdf 通过 Intent.getData() 暴露在应用程序之外
【发布时间】:2019-11-06 23:00:58
【问题描述】:

这是我的代码:

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()暴露在应用之外

【问题讨论】:

标签: java android


【解决方案1】:
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 

StrictMode.setVmPolicy(builder.build());

【讨论】:

  • 当添加@Vishal Bhut
  • 活动截图并保存为pdf文件@Zun
  • 不是你,我是想问@vishal
猜你喜欢
  • 2018-08-06
  • 1970-01-01
  • 2021-11-28
  • 2018-06-15
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
相关资源
最近更新 更多