Phonegap中的文件权限

时间:2014-02-04 08:07:58

标签: android cordova

我正在使用this方法尝试下载文件。 但是在“getFile”调用中,我得到的只是错误代码9,应该是权限错误。

我正在使用build.phonegap.com来构建我的应用。 在配置文件中,我添加了插件和权限。

    <gap:plugin name="org.apache.cordova.file" />
    <gap:plugin name="org.apache.cordova.file-transfer" />
    <feature name="http://api.phonegap.com/1.0/file"/>

phonegap版本为3.1.0。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

我相信你不要使用getFile而是调用(readAsText)

以下示例代码:

function win(file) {
var reader = new FileReader();
reader.onloadend = function (evt) {
    console.log("read success");
    console.log(evt.target.result);
};
reader.readAsText(file);
 };

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

entry.file(win, fail);

有关详细信息,请参阅Phonegap API文档: http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileReader