标签:
使用utuils框架在线升级,显示progressDialog,下载完成后自动弹出安装界面。
1 private void updateDownload() { 2 //检测内存设备是否可用 3 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ 4 //设置存储路径 5 final String targer = Environment.getExternalStorageDirectory() + "/update.apk"; 6 Log.e("test","存储路径:" + targer); 7 HttpUtils utils = new HttpUtils(); 8 Log.e("test","创建httputils"); 9 10 utils.download(mDownloadUrl, targer, new RequestCallBack<File>() { 11 //设置progressDialog 12 ProgressDialog progressDialog = new ProgressDialog(SplashActivity.this); 13 //更新下载进度 14 @Override 15 public void onLoading(long total, long current, boolean isUploading) { 16 super.onLoading(total, current, isUploading); 17 LogUtils.e("进度:" + current); 18 progressDialog.setTitle("正在下载:"); 19 20 //以百分比的形式设置当前下载进度 21 int bar = (int) (current*100/total); 22 progressDialog.setMessage("当前下载:" + bar + "%"); 23 //将progress显示出来 24 progressDialog.show(); 25 } 26 27 //成功 28 @Override 29 public void onSuccess(ResponseInfo<File> responseInfo) { 30 Log.e("test","下载成功"); 31 //打开安装包 32 Intent intent = new Intent(Intent.ACTION_VIEW); 33 intent.addCategory(Intent.CATEGORY_DEFAULT); 34 intent.setDataAndType(Uri.fromFile(responseInfo.result), 35 "application/vnd.android.package-archive"); 36 // startActivity(intent); 37 // 如果用户取消安装的话,会返回结果,回调方法onActivityResult 38 startActivityForResult(intent, 0); 39 } 40 41 //失败 42 @Override 43 public void onFailure(HttpException e, String s) { 44 Toast.makeText(SplashActivity.this,"下载失败",Toast.LENGTH_SHORT); 45 enterHome(); 46 } 47 48 }); 49 } else { 50 //没有内存卡 51 Toast.makeText(SplashActivity.this,"未检测到存储设备",Toast.LENGTH_SHORT); 52 enterHome(); 53 } 54 55 } 56 57 //用户取消安装软件时 58 @Override 59 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 60 super.onActivityResult(requestCode, resultCode, data); 61 enterHome(); 62 }
软件更新相关,使用utuils框架在线升级,显示progressDialog,下载完成后自动弹出安装界面。
标签:
原文地址:http://www.cnblogs.com/sdwfqin/p/5243141.html