cordova文件传输下载方法returns undefined undefined in error message

File transfer download method with cordova returns undefined undefined in error message

我的主要目标是将 canvas 转换为图像并下载。但是我什至无法从静态 url 下载图像。 我下载图像的代码(根据文档)如下...

     let filePath = cordova.file.externalRootDirectory + 'download/' + 'myImage.png';
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(){alert("s")},function(){alert("f")});
     alert(filePath)
     let fileTransfer = new window.FileTransfer();
     let uri = encodeURI("http://developer.android.com/assets/images/home/ics-android.png")
     alert("1")
     fileTransfer.download(uri, filePath,
           function (entry) {
                 alert("2")
                 console.log('Successfully downloaded file, full path is ' + entry.fullPath)
                 console.log(entry)
           },
           function (error) {
                 alert(error[0] + " " + error[1])
                 console.log('error')
                 console.log(error)
           },
           false
    )

我可以访问文件系统,但 doanload 函数总是执行错误回调,错误 [0] 未定义,错误 [1] 也未定义。

终于找到解决办法了。这只是因为权限。在 api23 以上,android 在安装应用程序时不询问权限。给予适当的权限后,它工作正常。