我的目的是执行后台传输以更新我的android cordova应用程序。 我正在尝试从我的网络服务器下载apk,然后我想使用WebIntent插件来启动应用更新。
然而,当我启动下载系统时出现错误“错误不支持的路径/data/user/0/io.cordova.myapp88c1a0/files/files/newpackage.apk”
以下是代码,真正感谢任何帮助:
function downloadFile(uriString, targetFile) {
var complete = function() {
alert('Done');
};
var error = function (err) {
console.log('Error: ' + err);
alert('error ' + err);
};
var progress = function (p)
{
console.log(p);
}
try {
var downloader = new BackgroundTransfer.BackgroundDownloader();
// Create a new download operation.
var download = downloader.createDownload(uriString, targetFile);
// Start the download and persist the promise to be able to cancel the download.
var promise = download.startAsync().then(complete, error, progress);
} catch(err) {
console.log('Error: ' + err);
}
};
function startDownload () {
alert('start download');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(fileName, { create: true }, function (newFile) {
alert(uriString);
alert(newFile);
downloadFile(uriString, newFile);
});
},
function (e)
{
var msg = '';
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
};
alert('Error: ' + msg);
}
);
}