javascript – file opener 2 is just not working with api degree 34 (Android 14)

0
25
javascript – file opener 2 is just not working with api degree 34 (Android 14)


I’m making an attempt to open a pdf file simply after downloading it through cordova file switch plugin. Even after downloading it and passing the very same path in fileOpener2.open operate, i get file not discovered. It doesn’t matter the place the file is being saved i simply need the file to be displayed simply after the obtain button click on.

i attempted utilizing each cordova.file.* to set a path for obtain and use the identical path to open however i get the identical error since. If fileopener2 is just not handy i’m okay to make use of one other plugin simply to open a downloaded pdf file. I do know in regards to the scoped storage stuff in new androids and fileopener2 is just not maintained now however i need one thing to work as the duty is very simple however resulting from lack of information in android dev, i’m unable to realize this for the previous 2 weeks. I need for each android and ios.

Under is my present code

operate downloadFile() {
// Distant URL of the PDF file
var fileUrl =
“”;

      // Native filesystem URL the place the file will probably be saved
      var targetPath =
        cordova.file.externalApplicationStorageDirectory +
        "CRS_Form" +
        ".pdf"; // You'll be able to change the goal path as wanted

      // Verify if the FileTransfer plugin is obtainable
      if (typeof FileTransfer !== "undefined") {
        // Initialize the File Switch Plugin
        var fileTransfer = new FileTransfer();

        // Outline the choices for the obtain
        var choices = {
          trustAllHosts: true, // Set this to true if you happen to're utilizing a self-signed SSL certificates
        };

        // Begin the obtain
        fileTransfer.obtain(
          fileUrl,
          targetPath,
          operate (entry) {
            // Success callback
            console.log("Obtain success! File saved to: " + entry.toURL());
            // You'll be able to carry out further actions right here after profitable obtain
            cordova.plugins.fileOpener2.open(targetPath, "software/pdf", {
              error: operate (e) {
                console.log(
                  "Error standing: " +
                    e.standing +
                    " - Error message: " +
                    e.message
                );
              },
              success: operate () {
                console.log("file opened efficiently");
              },
            });
          },
          operate (error) {
            // Error callback
            console.error("Obtain error: " + JSON.stringify(error));
          },
          choices
        );
      } else {
        // Deal with the case when the FileTransfer plugin is just not out there
        console.error("FileTransfer plugin not out there.");
      }
    }

getting error: file not discovered within the line

cordova.plugins.fileOpener2.open(targetPath, “software/pdf”, {
error: operate (e)

LEAVE A REPLY

Please enter your comment!
Please enter your name here