I'm trying to get an backup file from downloads folder by an intent. The intent picker work's fine
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.type = "application/zip"
intent.flags = FLAG_GRANT_READ_URI_PERMISSION
registerForActivityResult.launch(intent)
in the file result i'm trying like this:
try {
val path: String = data.dataString.toString()
val uri = FileProvider.getUriForFile(this, applicationContext.packageName.toString() + ".provider", File(path))
val file = File(uri.path.toString())
if (file.exists()) {
restoreDatabase()
}
else{
//error
}
} catch (e: Exception) {
Log.e("pickFile", e.toString())
}
int the exception i'm getting the error (the error ocurrs in line: val uri = FileProvider.getUriForFile..... ):
"java.lang.IllegalArgumentException: Failed to find configured root that contains /content:/com.android.externalstorage.documents/document/primary%3ADownload%2Fdatabase.zip"
i have an provider configured:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="myPackage.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
providers xml
<paths>
<external-files-path
name="external_files"
path="." />
<external-path
name="external"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>