0

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?

3
  • path="." is quite likely not correct. Commented Jan 27 at 20:52
  • Looks like it is not possible. Commented Jan 28 at 7:05
  • @MartinZeitler all good with that. I can open Files with write permission on android after manipulating the plugin. You have to set the write permission at the same place where read permission is set. But it seems that there is no solution like this for IOS possible. Maybe thats the reason why this feature is not added. Commented Feb 26 at 12:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.