这是我的代码:
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()
在应用程序之外公开
答案 0 :(得分:0)
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());