LocalFileSystem is not defined PhoneGap (Build) in Android

匿名 (未验证) 提交于 2019-12-03 02:54:01

问题:

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="you@example.com"> 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?

回答1:

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.



回答2:

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

write these lines in android manifiest file



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!