apicloud 后台下载带进度并打开安装APK


function aa(){

		downloadManager = api.require('downloadManager');

		downloadManager.enqueue({
		    url: 'http://www.oschina.net/uploads/osc-android-v2.6.7-oschina-release.apk',
		    //savePath: 'fs://count_v2_20161115.apk',
		    cache: false,
		    allowResume: true,
		    uncompress:false,
		    title: '教程',
		    networkTypes: 'all'
		}, function(ret, err) {

		    if (ret) {
		    	downid = ret.id;
		    	bb();
		    	/*
		        downloadManager.openDownloadedFile({
				    id: ret.id
				}, function(ret, err) {
				    if (ret.status) {
				        alert(JSON.stringify(ret));
				    } else {
				        alert(JSON.stringify(err));
				    }
				});
				*/
		    } else {
		        alert(JSON.stringify(err));
		    }

		});
		return false;
	}
	//查询下载进度
	function bb(){		
	    downloadManager.query({
		    ids: [
		        downid
		    ]
		}, function(ret, err) {
		    if (ret) {
			    var t = parseInt(ret.data[0].totalSize);
			    var f = ret.data[0].finishSize;
		        if(t >0) $('#aaa').html('总大小:'+t+',已下载:'+f);
		        if(ret.data[0].status != 3) setTimeout('bb()',1000);
		    } else {
		        //alert(JSON.stringify(err));
		    }
		});
		
	}

转载于:https://my.oschina.net/ailonjien/blog/789104

你可能感兴趣的:(apicloud 后台下载带进度并打开安装APK)