【发布时间】:2017-06-06 22:02:03
【问题描述】:
我试图在从服务器下载 pdf 文件并将其存储在内部存储中后访问它。问题是在成功下载文件后,它会在一瞬间打开然后立即关闭。请有人告诉我正确的方法是什么。先感谢您。
这是我下载 pdf 文件的代码:
文件 file = new File(getFilesDir(),"pdfFolder");
if(!file.isDirectory()) 文件.mkdirs();
文件输出文件 = 新文件(文件, "samples.pdf");
//URL连接....
//输入流....
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
这是查看我的 pdf 文件的代码:
文件 pdfFile = new File(getFilesDir(),"/pdfFolder/samples.pdf");
意图 pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(Uri.fromFile(pdfFile),"application/pdf"); pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
开始活动(pdfIntent);
注意:绝对路径指向这个“/data/user/0/com.package.name/pdfFolder/sample.pdf”
【问题讨论】:
标签: android android-studio pdf android-intent