Home > Software engineering >  Problems ataching file from cache folder
Problems ataching file from cache folder

Time:05-05

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:

<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

CodePudding user response:

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

  • Related