You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何配置FileProvider的file_paths.xml匹配指定下载路径?

Correct FileProvider Setup for Your Private External Download Directory

Got it, let's fix this FileProvider path issue once and for all. Your APK is stored in the private external files directory of your app specifically under the Download subfolder, so we need to use the right path tag in file_paths.xml that maps directly to this location.

Step 1: The Correct file_paths.xml Configuration

Replace your existing file content with this:

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

Why This Works (And Why Your Previous Attempts Failed)

Let's break down the details:

  • external-files-path: This tag is designed explicitly for mapping the directory returned by Context.getExternalFilesDir(null) — which is exactly the root path you're using with SetDestinationInExternalFilesDir (/storage/emulated/0/Android/data/com.myco.myapp/files/).
  • name="app_downloads": This is just a friendly placeholder that will appear in the generated Content URI (e.g., content://com.myco.myapp.fileprovider/app_downloads/com.myco.myapp.version.apk). You can rename this to anything meaningful for your app.
  • path="Download/": This points to the Download subfolder relative to the root of your app's external files directory. No leading slash needed here since it's a relative path.

Your earlier issues happened because:

  • Using tags like external-path targets the public external storage root (/storage/emulated/0/), which doesn't align with your app's private directory — hence the IllegalArgumentException.
  • The root-path hack matches all paths but produces malformed URIs (with the file:/ prefix baked in) that the system can't properly resolve for installation.

What the Generated URI Will Look Like

With this configuration, GetUriForFile will output a valid Content URI like:
content://com.myco.myapp.fileprovider/app_downloads/com.myco.myapp.version.apk
This URI is fully compatible with Android's file access rules and will work for app installation.

Quick Checks to Avoid Issues

  • Make sure your apkPath variable is a plain file path (no file:/ prefix) — it should be /storage/emulated/0/Android/data/com.myco.myapp/files/Download/com.myco.myapp.version.apk.
  • If you're using AndroidX instead of the old support library, just update the provider name in your Manifest to androidx.core.content.FileProvider — the file_paths.xml configuration stays identical.

内容的提问来源于stack exchange,提问作者Brian T

火山引擎 最新活动