java - 在android studio上打开pdf文件并打开黑屏pdf

标签 java android pdf provider

Emulator .尝试通过文件提供程序打开存储在模拟器中的pdf文件。问题是 pdf 打开但其内容为空(黑屏)。谢谢!

            File item = new File("/storage/emulated/0/Download/theoretical_computer_science_cheat_sheet.pdf");
            Uri uri = FileProvider.getUriForFile(MainActivity.this[enter image description here][1],getApplicationContext().getPackageName() + ".share",item);
            //Uri uri = getUriForFile(getBaseContext(), getApplicationContext().getPackageName() + ".share",item);
            Intent intent = new Intent(Intent.ACTION_VIEW,uri);
            intent.setDataAndType(uri,"application/pdf");

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            try {
                getApplicationContext().startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // Instruct the user to install a PDF reader here, or something
            }

最佳答案

尝试先加载该 pdf 文件?我怀疑您的 PDF 阅读器会自行加载。

关于java - 在android studio上打开pdf文件并打开黑屏pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56282555/

相关文章:

java - 混合 C/Java OSGi 平台

java - 无法连接到 PostgreSQLContainer : java. io.EOFException

android - 启动应用程序时 react native android 错误

java - LayoutWeights 无法正确缩放元素

php - mPDF 未在生成的 PDF 中显示图像,而是显示红色 x 符号和背景图像的完整 url

javascript - Uncaught Error : [$injector:modulerr] on attempting to load a pdf print page

java - 获取Firefox驱动后不执行语句

java - 修改 IntelliJ 为 Maven 项目的 Tomcat 或 Jetty 配置的资源创建符号链接(symbolic link)

android - 在双卡 android 中禁用数据连接

c# - 如何将 Windows 窗体保存为 pdf