Uncaught ReferenceError: LocalFileSystem not defined in CORDOVA

I considered a lot of questions, but this did not solve my problem.
I have already installed the plugin for files.
When I type the cordova ls plugin, I get the following result:

[ 'org.apache.cordova.file' ]

In androidmanifest.xml I have:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

And in app / res / xml / config.xml I have:

<feature name="File">
    <param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>

This is my code:

document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.file(gotFile, fail);
}

function gotFile(file){
    readDataUrl(file);
    readAsText(file);
}

function readDataUrl(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as data URL");
        console.log(evt.target.result);
    };
    reader.readAsDataURL(file);
}

function readAsText(file) {
    var reader = new FileReader();
    reader.onloadend = function(evt) {
        console.log("Read as text");
        console.log(evt.target.result);
        document.getElementById('file_status').innerHTML = evt.target.result;
    };
    reader.readAsText(file);
}

function fail(error) {
    console.log(error.code);
}

What did I do wrong?

+3
source share
1 answer

I just worked on this problem a lot.

For me it was that jquery document ready events do not fire on Android (Cordova, Phonegap) , even if you use the Crosswalk engine!

You need to switch any events ready for the document to:

Html:

<body onload="onLoad()">

Js:

function onLoad()
{
    document.addEventListener("deviceready", onDeviceReady, false);
}
+1
source

All Articles