在Phonegap App中获取错误代码5

时间:2014-04-01 15:07:23

标签: android cordova

我正在开发一个phonegap应用。在我的应用程序中,用户可以下载pdf,jpg等文件......

我找到了一些教程,但目前我无法创建文件。这是我的javascript 代码:

var remoteFile = 'http://src/to/an/image.jpg';
var localName = 'abcd.jpg';

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {

    fileSystem.root.getFile(
     localName ,
     {create : true, exclusive : false},
     function(file) {
     alert('SUCCESS');
     },
     function(error) {
         // I get error code 5...
     alert(error.code);
     });
}, 
function(err) {});

插件"文件"和"文件传输"已安装。 在AndroidManifest.xml中我添加:

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

我还将jpg文件的url添加到白名单中。 在config.xml中:

<access origin="*"/> 

Logcat说:

enter image description here

有谁知道可能出现什么问题?

提前致谢。

1 个答案:

答案 0 :(得分:0)

万一你遇到和我一样的问题,我的问题是我给文件一个包含无效字符的名字。我正在构建一个记录应用程序事件的系统,我创建了这样的文件:

dir.getFile("log123-" + new Date().toString() + ".txt", ...

我使用了一个更好的名字,它有效!