首页 > 解决方案 > 如何通过 Android Intent 使用外部应用程序打开 3D-PDF 文件

问题描述

我在我的 Android 应用程序中下载了一个 3D-PDF 文件,我想通过 Intent 在外部应用程序中打开它。我使用“3D PDF Reader”作为外部应用程序。

这是Java中的源代码:

        Uri fileUri = FileProvider.getUriForFile(MainActivity.this,
                BuildConfig.APPLICATION_ID + ".provider", file);
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(fileUri, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            showMessage("Keine App zur Anzeige von PDF-Dokumenten gefunden!");
        }

错误消息是:“抱歉,无法从此 PDF 加载 3D 内容。该文档受保护或不包含 3D 内容。”

我可以使用此代码在外部应用程序中显示普通 PDF 文件。当我使用应用程序“Total Commander”(文件管理器应用程序)单击由我的应用程序下载的 3D-PDF 时,我可以在外部应用程序(“3D PDF 阅读器”)中加载 3D-PDF 文件)。所以一定有可能实现我的目标。

很感谢任何形式的帮助。

标签: androidpdfandroid-intent

解决方案


推荐阅读