PDF 查看器要求输入密码,但没有为 pdf 文件设置密码

Pdf viewer asking for password but no password is set for pdf file

我正在尝试从我的应用程序的资产文件夹中打开一个 pdf 文件。

我使用了这个代码。

            File pdfFile = new File("file:///android_asset/c.pdf");
            Uri path = Uri.fromFile(pdfFile);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setDataAndType(path, "application/pdf");
            startActivity(intent);

我的 pdf 文件没有设置密码,但 "OfficeSuite" 在我尝试打开时要求输入密码。

怎么办?

我尝试了几个文件。

其他应用无法从您的应用打开 file:///android_asset 路径。

使用 ContentProvider 将 PDF 流式传输到其他应用程序。 My StreamProvider offers an out-of-the-box solution for this. Or, copy the PDF to your internal storage and use FileProvider, as shown in this sample app. Or, copy the file to external storage and use Uri.fromFile() to generate a Uri pointing to that, though this will work with fewer and fewer apps over time.