//程序检查更新时,从服务器下载最新apk private void download(final Context context){ //File sdCardFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()); final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "/11AXP_PACKET_LastVer_dev.apk"); HttpUtils http = new HttpUtils(); HttpHandler handler = http.download("http://update.axpapp.com/appUpdate/downloadFile?filename=AXP_PACKET_LastVer_dev.apk", file.getAbsolutePath(), true, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。 false, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。***这个比较重要, new RequestCallBack<File>() { @Override public void onStart() { Log.v("updateAPK", "conn..."); UpdateAppDialog.showDialog(SplashActivity.this, "正在更新程序", "正在更新程序", "", null); } @Override public void onLoading(long total, long current, boolean isUploading) { Log.v("updateAPK", current + "/" + total); UpdateAppDialog.updateProgress((int)total/1024, (int)current/1024); } @Override public void onSuccess(ResponseInfo<File> responseInfo) { Log.v("updateAPK", responseInfo.result.getPath()); UpdateAppDialog.dissDialog(); CommandTools.install(file, context); } @Override public void onFailure(HttpException error, String msg) { Log.v("updateAPK", msg); } }); }
本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1873029
原文地址:http://670176656.blog.51cto.com/4500575/1873029