Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading file using Cordova File Plugin

I'm using cordova file plugin - cordova file plugin

I'm actually reading the file from the textfile. Below is my code

document.addEventListener("deviceready", function () {  
    window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "sameple.txt", gotFile, fail);
}, true);

function gotFile(file) {           
    file.file(function (file) {                
        var reader = new FileReader();
        reader.onloadend = function (evt) {          
            console.log(this.result);
        }
        reader.readAsText(file);                
    }, fail());            
}

function fail(e) {
    console.info("FileSystem Error : " + e);
}

So whenever i run this code, i'm getting the below error

deviceready has not fired after 5 seconds.
Channel not fired: onPluginsReady
Channel not fired: onCordovaReady

Could not get Cordova FileSystem: Error: deviceready has not fired after 5 seconds.
   "Could not get Cordova FileSystem:"
   {
      [functions]: ,
      __proto__: { },
      description: "deviceready has not fired after 5 seconds.",
      message: "deviceready has not fired after 5 seconds.",
      name: "Error"
   }

{"data":"data"}

After deviceready error later i'm able to get the exact data.. How do i resolve this error? do i have to wait for the device ready execution to complete?

like image 963
Matarishvan Avatar asked Aug 10 '17 08:08

Matarishvan


1 Answers

It can happen for a number of reasons, see here more details.

You should try firs @bayanAbuawad suggestion that works most of the times:

  1. Add the platforms with cordova platform add ios android

  2. Remove them with cordova platform remove ios android

  3. Add them again.

It is super weird, but it’s related to a faulty android.json and ios.json inside the platforms folder.

like image 151
dan Avatar answered Oct 09 '22 11:10

dan