Android Drive PDF Viewer,打开时出现意向问题

时间:2018-10-21 18:45:08

标签: java android pdf android-intent

在我们的代码中,有一段代码可以向用户显示生成的PDF文档:

   public static final String PATH = FileUtils.buildPath(Environment.getExternalStorageDirectory().toString(), "temp.pdf"); // /sdcard/temp.pdf

  // ...
   File file = new File(PDFPrinter.PATH);
                if(file.exists() == true){
                    Uri uri = Uri.fromFile(file); 
                    Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
                    pdfIntent.setDataAndType(uri, "application/pdf");
                    pdfIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getContext().startActivity(pdfIntent);
}

但是它不能与典型的Drive PDF查看器一起正常工作,有时它不会打开新生成的文档版本,而是向用户显示以前的版本。为什么会发生?


我找到了添加一个标志的修补程序

                pdfIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                pdfIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //+

但是我赶不上它为什么起作用?

0 个答案:

没有答案