I'm trying to open files from my ionic app (for example editable pdf files in third party apps like PDF editors) using the Capacitor FileOpener. But i alway get the files opened with writeprotection.
I tried all available Capacitor Filesystem Directories.
Inside my AndroidManifest I included following information (shortened):
<application ...
android:requestLegacyExternalStorage="true"aasf
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>
...
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
my file_paths looks like:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
The files can be stored on each tried Directory (except EXTERNAL_STORAGE since its not avalilable on Andorid 11 and above).
My function for opening the files looks like:
async open() {
const path = await Filesystem.getUri({
path: `files/${this.file.fileName}`,
directory: this.dataService.fileDirectory,
});
await Filesystem.requestPermissions();
if(path.uri) {
await FileOpener.open({
filePath: path.uri
}).catch((err: unknown) => {
console.log(err);
});
}
}
Where this.dataService.fileDirectory equals an directory of Capacitor Filesystem Directory like Directory.Documents.
But no matter in what Directory the File is stored, it will always be opened with write protection. But i need to be able to access and edit the files using third party apps.
Do I miss anything? Or is this not possible using Ionic and Capacitor? If its possible, would it also be possible on IOs?
path="."is quite likely not correct.