cordova 下载更新

function UpdateForAndroid(downloadUrl) {
$ionicLoading.show({
template: "已经下载:0%"
});
var targetPath ="file:///storage/sdcard0/Download/yuetui.apk";
  var trustHosts = true;
var options = {};
$cordovaFileTransfer.download(downloadUrl, targetPath, options, trustHosts).then(function (result) {
$cordovaFileOpener2.open(targetPath, 'application/vnd.android.package-archive'
).then(function () {
// 成功
}, function (err) {
console.log(err);
});
$ionicLoading.hide();
}, function (err) {
$ionicLoading.show({
template: "下载失败"
});
$ionicLoading.hide();
}, function (progress) {
$timeout(function () {
var downloadProgress = (progress.loaded / progress.total) * 100;
$ionicLoading.show({
template: "已经下载:" + Math.floor(downloadProgress) + "%"
});
if (downloadProgress > 99) {
$ionicLoading.hide();
}
});
});
}
网上找的这种方式,能实现APP的下载更新,但存在些问题,
1.存在SD卡的情况下,不会自已更新完后,打开APP,
2.可能没有存在SD卡的情况下,需要判断。
3.目前大部分APP都有用的android系统默认的下载安装器downloadmanager,cordova没找到此类方式(考虑写一个)
4.由于项目时间的需要,赞改成浏览器打开下载。
posted @ 2016-12-10 21:24  广拓小程序  阅读(318)  评论(0编辑  收藏  举报