LocalFileSystem is not defined PhoneGap (Build) in Android

I have the following code:

function wait(){
    $(document).ready(function() {
        //alert("Dentro de ready");
        document.addEventListener("deviceready", init(), true);
    });
}

Where "wait" is a Javascript function called from the onload event. I use the onload event, as well as $(document).ready and "deviceready" event to make sure every single thing is loaded when i start coding.

The "init()" method does a few things and then calls the following method:

function download_img(imgToDownload){
    var url = remote_url+imgToDownload; // image url
    alert("img url: "+url);     
    try{
    window.requestFileSystem(**LocalFileSystem**.PERSISTENT, 0, 
            function (fs) {
        var imagePath = fs.root.fullPath +"/"+ imgToDownload; // full file path
        var fileTransfer = new FileTransfer();
        fileTransfer.download(url, imagePath, 
            function (entry) {
            alert("OK: " + entry.fullPath); // entry is fileEntry object
            }, 
            function (error) {
                alert("download error source " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
            alert("http_status"+error.http_status);
            }
        );
        }
    );
    }catch(err){
    alert(err.message);
    }
}

Where I get the error message: "LocalFileSystem is not defined".

My config.xml is:

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
    xmlns:gap = "http://phonegap.com/ns/1.0"
    id        = "com.lamakun.mancomunidad"
    version   = "3.0.0">

<name>PhoneGap Build Application</name>

<description>
A simple PhoneGap Build application.
</description>

<author href="https://example.com" email="[email protected]">
Your Name
</author>
<preference name="phonegap-version" value="2.2.0" />


<access origin="http://www.mytests.es" subdomains="true"/>

</widget>

In case I might add any permission, even though I think right now I have them all. Can anyone give me a clue on that?

Upvotes: 0

Views: 4993

Answers (2)

Ashisha Nautiyal
Ashisha Nautiyal

Reputation: 1397

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

write these lines in android manifiest file

Upvotes: 0

Simon MacDonald
Simon MacDonald

Reputation: 23273

It isn't:

document.addEventListener("deviceready", init(), true); 

it should be:

document.addEventListener("deviceready", init, true); 

having the () after init calls that function immediately before the deviceready event is fired.

Upvotes: 1

Related Questions