javascript window.resolveLocalFileSystemURI 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29965452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:24:08  来源:igfitidea点击:

window.resolveLocalFileSystemURI is not a function

javascriptandroidangularjscordovafile-io

提问by Khalid

I created a web application that I need to convert to a mobile application, now all I have is html5/js/css files which means I don't have any www foder no platforms folder, not a cordova project ... I started first to build the app using cordova command lines, but I couldn't, I found many problems on that, I used then https://build.phonegap.com/, and it works fine for me. In order to read the file, I have tried this code :

我创建了一个需要转换为移动应用程序的 Web 应用程序,现在我只有 html5/js/css 文件,这意味着我没有任何 www foder noplatforms 文件夹,而不是cordova 项目......我首先开始使用cordova命令行构建应用程序,但我不能,我发现了很多问题,然后我使用了https://build.phonegap.com/,它对我来说很好用。为了读取文件,我尝试了以下代码:

    window.resolveLocalFileSystemURI("file:///android_asset/www/data/User.xml", function () {
        alert("Success");
    }, function () {
        alert(" error ");
    });

but, it didn't work. I added a try catch, the exception was :

但是,它没有用。我添加了一个try catch,例外是:

window.resolveLocalFileSystemURI is not a function

Do i need to add something to my code to make it work ?

我需要在我的代码中添加一些东西才能让它工作吗?

回答by Assaf Hershko

You need to install a plugin for this to work.

你需要安装一个插件才能工作。

Basically, run "cordova plugin add org.apache.cordova.file" at your application's root directory.

基本上,在应用程序的根目录中运行“cordova plugin add org.apache.cordova.file”。

For detailed instructions see here, under "Accessing the Feature": http://docs.phonegap.com/en/edge/cordova_file_file.md.html#LocalFileSystem

有关详细说明,请参阅此处的“访问功能”下:http: //docs.phonegap.com/en/edge/cordova_file_file.md.html#LocalFileSystem

UPDATE 2019

2019 年更新

The correct way to add this plugin is now with this command in your project root:

添加此插件的正确方法现在是在项目根目录中使用以下命令:

cordova plugin add cordova-plugin-file

This is a core cordova plugin. Documentation found here on npm

这是一个核心的cordova插件。在 npm 上找到的文档