Problem with FileOpener to open a pdf on android

Viewed 24

I use PdfMake to generate a pdf file, it works well in web version, but not on android 11

My code to generate the pdf :

if (platform != "web") {
  pdfFile.getBase64((data) => {
    try {
      Filesystem.writeFile({
        path: nameFile,
        data: data,
        directory: Directory.Documents,
        //encoding: Encoding.UTF8,
        recursive: true,
      }).then(() => {
        Filesystem.getUri({
          directory: Directory.Documents,
          path: nameFile,
        }).then(
          (getUriResult) => {
            const path = getUriResult.uri;
            console.log("path : " + path);
            FileOpener.open(path, "application/pdf")
              .then(() => console.log("File is opened"))
              .catch(
                (error) => console.log("Error openening file", error),
                (error) => console.dir(error, {
                  depth: null
                })
              );
          },
          (error) => {
            console.log(error);
          }
        );
      });
    } catch (error) {
      console.error("Unable to write file", error);
    }
  });
} else {
  pdfFile.download(`${nameFile}`);
}

The problem comes when I do the fileOpener.open I go directly into the catch I get this error :

{status: 9, message: "Activity not found: No Activity found to handle In…X-1663759802589.pdf typ=application/pdf flg=0x3 }"}

"Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.company.appname.fileOpener2.provider/external/Documents/XX-1663759802589.pdf typ=application/pdf flg=0x3 }"

I first thought it was a permission problem, so I checked my ManifestAndroid but I really don't know what the problem is.

AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>

<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    tools:ignore="ScopedStorage" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
        android:name="com.company.appname.MainActivity"
        android:exported="true"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBarLaunch"
        android:launchMode="singleTask"
        android:screenOrientation="userLandscape">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <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>
</application>
0 Answers
Related