【问题标题】:FileProvider : Install apk programatically - Failed to find configured root that containsFileProvider:以编程方式安装 apk - 找不到配置的根目录,其中包含
【发布时间】:2023-04-11 04:56:01
【问题描述】:

我正在使用 FileProvider 从我的应用程序安装 apk。关注了许多stackoverflow问题,但仍然面临这个问题

 java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.tssi.myapptour/files/download/myapp_newSigned.apk

清单中的我的提供者

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.tssi.myapptour.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

我的文件路径.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="download" path="download/" />

   <!-- <external-path name="download" path="Android/data/com.tssi.myapptour/files/download/" />-->

</paths>

还有我调用apk的代码

String strApkToInstall = "myapp_newSigned.apk";
File fileApkToInstall = new File(getExternalFilesDir("download"), strApkToInstall);

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri fileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",
        fileApkToInstall);
intent.setDataAndType(fileUri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);

【问题讨论】:

    标签: android android-install-apk android-fileprovider


    【解决方案1】:

    您的文件位于getExternalFilesDir()。这与 FileProvider 元数据中的 files-path 不匹配。要么:

    • 切换到getFilesDir()(从安全角度来看,这是一个更好的解决方案),或者

    • 切换到external-files-path

    有关文件系统位置和元数据条目之间映射的更多信息,请参阅the FileProvider documentation

    【讨论】:

    • 让它成为路径="."
    猜你喜欢
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多