java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/test/app.apk

0

Hi, I have a problem using FileProvider, it gives me this exception:

  

java.lang.IllegalArgumentException: Failed to find set root   that contains /storage/emulated/0/test/app.apk

This is part of my AndroidManifest.xml:                    

...

<application
...
<provider
    android:name="android.support.v4.content.FileProvider"
    android:grantUriPermissions="true"
    android:exported="false"
    android:authorities="com.prueba.fileprovider">

    <meta-data
         android:name="android.support.FILE_PROVIDER_PATHS"
         android:resource="@xml/file_provider_paths"/>
</provider>
...

This is my file_provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <cache-path name="cache" path="." />
    <external-files-path name="external-files" path="." />
</paths>

I am downloading an .apk file in the external memory (the download works correctly in any version, but access to this error from android 7.0.0, now I am adapting it with FileProvider for 7.0.0 or more), with this code within an activity and I want to launch it, but I skipped the exception before:

    String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/prueba/";

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

File file = new File(path + "app.apk");
                                                intent.setData(FileProvider.getUriForFile(getApplicationContext(), "com.obralia.barcodescanningapp.fileprovider", file));
                                                intent.setType("application/vnd.android.package-archive");

What can I do? thanks

    
asked by Santiago 09.04.2018 в 11:04
source

0 answers