gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:57:53 26 4
gpt4 key购买 nike

这是我的代码:

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 exposed beyond app through Intent.getData()

最佳答案

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

StrictMode.setVmPolicy(builder.build());

关于java - 如何修复 android.os.FileUriExposedException : file:///storage/emulated/0/Documents/SM. pdf 通过 Intent.getData() 暴露在应用程序之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56748402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com