【发布时间】:2016-04-14 16:33:11
【问题描述】:
我正在尝试从服务器 url 下载并保存 apk。但我无法下载并保存。你能帮我解决这个问题吗?
代码:
onDeviceReady: function() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
app.receivedEvent('deviceready');
myApp.start(); //this is where I put the call to my App's functionality relying on device APIs
}
function gotFS(fileSystem) {
window.fileSystem = fileSystem;
fileSystem.root.getDirectory(window.appRootDirName, {
create: true,
exclusive: false
}, dirReady, fail);
}
function dirReady(entry) {
window.appRootDir = entry;
console.log("application dir is ready");
// alert("ready");
var fileTransfer = new FileTransfer();
var url = "http://www.something.org/Android/Sample.apk";
var filePath = window.appRootDir.toURL() + "Sample.apk";
alert(filePath);
var uri = encodeURI(url.android);
fileTransfer.download(
uri, filePath, function(entry) {
alert("download complete: " + entry.fullPath);
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'file://' + entry.fullPath,
type: 'application/vnd.android.package-archive'
},
function(){
console.log("Success");
},
function(e){
alert('Error launching app update');
}
);
}, function(error) {
alert("download error" + error.codename);
});
}
【问题讨论】:
标签: javascript android html cordova