Phonegap Android LocalFileSystem is not defined

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

问题:

I have a problem for accessing Android File System for storage purpose in my phonegap application. I've searched and found lots of not-my-situation solutions!

I know about the necessity of deviceready to be fired and checked and it got fired. So the phonegap.js is loaded perfectly!

I think I requested the file permissions and have features in my manifest and config file. here they are:

config.xml:

    

AndroidManifest.xml:

and here is the error throwing part of my code:

$(document).ready(function () {     document.addEventListener("deviceready", onDeviceReady, false); }); function onDeviceReady() {     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { //throws the 'Uncaught ReferenceError: LocalFileSystem is not defined' error         fileSystem = fileSystem;     }, function (evt) {         alert(evt.target.error.code);     }); } 

But I get the error for a reason I don't have any idea about! Please give me your thought. I appreciate it very much.

PS: I'm using phonegap 3.0!

回答1:

Are you using phonegap cli to build your project? Then you might have missed adding the File plugin to your project. Besides configuring in config.xml and AndroidManifiest.xml you need the code for the plugin. You can add it to your project with:

$ phonegap plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git  

Check top of page in the docs: http://docs.phonegap.com/en/3.0.0/cordova_file_file.md.html#LocalFileSystem

You can also check the file android/assets/www/cordova_plugins.js to see if window.LocalFileSystem is actually defined. Look for somthing like this:

{     "file": "plugins/org.apache.cordova.core.file/www/FileSystem.js",     "id": "org.apache.cordova.core.file.FileSystem",     "clobbers": [         "window.FileSystem"     ] }, 


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