代码之家  ›  专栏  ›  技术社区  ›  Rajeev Kumar

文件提供程序中的IllegalArgumentException-Android 7.0

  •  2
  • Rajeev Kumar  · 技术社区  · 8 年前

    我正在尝试访问保存在中的apk文件 Download\AppName\myApk.apk 从我的应用程序使用 FileProvider 概念,但失败

    我正在使用以下代码

            Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
            File file = new File(location);     
            // location= Environment.getExternalStorageDirectory() + "/Download/AppName\MyApk.apk";      
            Uri uri = FileProvider.getUriForFile(Login.this, BuildConfig.APPLICATION_ID + ".fileprovider", file);
            intent.setData(uri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivityForResult(intent, INSTALL_APK_REQUEST_CODE);
    

    显示

    <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="xxx.xxx.xxx.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths"/>
        </provider>
    

    文件路径。xml

    <paths xmlns:android="http://schemas.android.com/apk/res/android">
      <files-path name="adbc" path="Download/AppName" />
    </paths>
    

    例外

    Failed to find configured root that contains /storage/emulated/0/Download/AppName/MyAPk.apk
    

    请帮忙!!!

    1 回复  |  直到 8 年前
        1
  •  4
  •   CommonsWare    8 年前

    替换:

    <files-path name="adbc" path="Download/AppName" />
    

    使用:

    <external-path name="adbc" path="Download/AppName" />
    
    推荐文章