Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法保存到Android和Apache Cordova 3.4.1上的文件_Android_Cordova - Fatal编程技术网

无法保存到Android和Apache Cordova 3.4.1上的文件

无法保存到Android和Apache Cordova 3.4.1上的文件,android,cordova,Android,Cordova,Cordova版本:3.4.1-0.1.0 我正在使用文件传输插件,无法将图像保存到文件中 从设备中获取的错误: “下载错误目标错误” 上传错误代码1 这是代码,有什么想法吗 var fileTransfer = new FileTransfer(), d = new Date(), testImageUrl = encodeURI('http://www.inutritie.ro/wp-content/uploads/2013/07/otet-600x300.jpg'),

Cordova版本:3.4.1-0.1.0

我正在使用文件传输插件,无法将图像保存到文件中

从设备中获取的错误: “下载错误目标错误” 上传错误代码1

这是代码,有什么想法吗

var fileTransfer = new FileTransfer(),
    d = new Date(),
    testImageUrl = encodeURI('http://www.inutritie.ro/wp-content/uploads/2013/07/otet-600x300.jpg'),
    imageCacheDir = '//Testdir';


fileTransfer.download(
    testImageUrl,
    'file:'+imageCacheDir+'/'+d.getTime(),
    function(entry){
        alert("download complete: " + entry.fullPath);
    },
    function(error){
        alert("download error source " + error.source);
        alert("download error target " + error.target);
        alert("upload error code" + error.code);
    }
);
以下是我如何设置并获取将图像保存到Android设备上的目录:

function initLocalCacheDir(){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
};

function onFileSystemSuccess(fileSystem) {
    fileSystem.root.getDirectory("Testdir",{create:true, exclusive: false}, gotDir, gotDirError);
};

function gotDir(d) {
    var imageCacheDir = d.fullPath;
};

function gotDirError(evt) {
    alert('gotDirError');
};

function onFileSystemFail(evt) {
    alert('onFileSystemFail');
};

Testdir存在吗?在保存文件之前,保存文件的目录必须存在。它不会为你创造它。