I am developing a function to catch and read KML files, and another function to unzip and save these files that are inside of KMZ files (basically a zip).
In the first attempt I could not access it because an error told me that I don't have de right permissions, but according to capacitor documentation and after add android:requestLegacyExternalStorage="true" in the AndroidManifest.xml, I could obtain the right permission to access the device files. After that I had to filter the URI using the function FilePath.resolveNativePath(path); from the FilePath. The original path is generated by fileChooser.open().then(uri=>{}) and the URI is the root path to the file.
After some tests with an Android emulator using API 29/v10 and API 30/v11 and then a physical Android device with API 29/v10, I was able to make the functions work, but in physical device there is a specific folder, Documents, that is inaccessible and generate a error:
"ERROR Error: Uncaught (in promise): Object: {"code":0,"message":"Unable to resolve filesystem path."}".
Page.ts:
selectFile(): Promise<void>{
if (this.platform.is('cordova')) {
return this.fileChooser.open().then(uri => {
return this.filePath.resolveNativePath(uri).then(uri => {
let filename = uri.split('/').pop();
this.layerName = filename;
this.fileURI = uri;
});
});
}
}
Edits
URI before the edition : content://com.android.externalstorage.documents/document/home%3Apoligono.kml.
URI after the edition : error occurs after run the function FilePath.resolveNativePath(uri);. This happens only in this specific folder, in the physical device.
