Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problems ataching file from cache folder

Im getting an exception when accesing file with File provider: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.mypackage.test/cache/.logs/app.log

Im just getting a file path and creating a File object with it and then calling FileProvider:

files.forEach {
    val file = File(it)
    val uri = FileProvider.getUriForFile(
        application,
        application.packageName + ".provider",
        file
    )
    putExtra(Intent.EXTRA_STREAM, uri)
}

Also added the provider in the manifest:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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>

and the xml with the provider paths:

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

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

I tried by changing the provider_paths from external-path to external-files-path and also tried with external-cache-path but still isnt working. I dont really understand what am i doing wrong.

I also saw that when i call cacheDir.absolutePath i get /data/user/0/com.mypackage.test/cache instead of /data/data/com.mypackage.test/cache

>Solution :

Use <cache-path>, not <external-path>, for files stored in getCacheDir(), which appears to be what you are using.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading