【问题标题】:Android PDF closes immediately after opening from Internal storageAndroid PDF 从内部存储打开后立即关闭
【发布时间】: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


    【解决方案1】:

    尝试设置

     pdfIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    

    而不是

    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

    它对我有用。

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2017-08-20
      • 2017-11-21
      • 2014-11-23
      • 2018-05-02
      • 2016-03-19
      相关资源
      最近更新 更多