无法使用 FileProvider 和外部 PDF 编辑器保存 PDF 文件

问题描述

我的应用程序的 Android/data/packagename 文件夹中有各种 PDF,需要能够编辑它们。通过例如打开Adobe Reader 工作没有任何问题,FileProvider 到目前为止工作正常。当我关闭 PDF 编辑器时,不会保存更改的文件。我尝试了不同的 PDF 编辑器。不幸的是,到目前为止我还没有找到任何其他选择。非常感谢您的帮助!

清单中的提供者

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true" >
    <Meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>

provider_paths.xml

<paths>
    <external-path name="external_files" path="."/>
</paths>

Java 代码

    public void openPDF(SetupFile setup) {
        File pdfFile = new File(this.getExternalFilesDir(null).getAbsolutePath() + "/setups",setup.getFileName());

        if (pdfFile.exists()) {
            try {
                Uri uri = FileProvider.getUriForFile(this.getContext(),this.getContext().getPackageName() + ".provider",pdfFile);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(uri,"application/pdf");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(fThis.getActivity(),getString(R.string.error_no_pdf_editor),Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(getActivity(),getString(R.string.error_file_not_exists),Toast.LENGTH_LONG).show();
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)