当前位置: 移动技术网 > 移动技术>移动开发>Android > Android okhttputils现在进度显示实例代码

Android okhttputils现在进度显示实例代码

2019年07月24日  | 移动技术网移动技术  | 我要评论

okhttputils是一款封装了okhttp的网络框架,支持大文件上传下载,上传进度回调,下载进度回调,表单上传(多文件和多参数一起上传),链式调用,整合gson,自动解析返回对象,支持https和自签名证书,支持cookie自动管理,扩展了统一的上传管理和下载管理功能。

 //download the new app
  private void downloadnewapp(newversion.xianzaishirfbean version) {
    if (stringutils.isempty(version.geturl())) {
      toastutils.showtoast("新版本的app url为空");
      enterloginactivity();
      return;
    }
    final progressdialog dialog = new progressdialog(this);
    dialog.settitle("正在下载");
    dialog.setmessage(version.getdes() + "");
    dialog.setcancelable(false);
    dialog.setprogressstyle(progressdialog.style_horizontal);
    dialog.show();
    if (!netutils.hasnet(splashactivity.this)) {
      toastutils.showtoast("请检查网络环境");
      return;
    }
    system.out.println("splashactivity.downloadnewapp=" + version.geturl());
    okhttputils
        .get()
        .url(version.geturl())
        .build()
        .execute(new filecallback(environment.getexternalstoragedirectory().getabsolutepath(), conts.new_app_name) {
          @override
          public void onerror(call call, exception e, int id) {
            enterloginactivity();
            system.out.println("splashactivity.onerror=哈哈哈");
            toastutils.showtoast("下载更新包失败");
          }
          @override
          public void inprogress(float progress, long total, int id) {
            super.inprogress(progress, total, id);
            dialog.setprogress((int) (100 * progress));
          }
          @override
          public void onresponse(file response, int id) {
            intent intent = new intent();
            intent.setaction(intent.action_view);
            intent.addcategory(intent.category_default);
            intent.setdataandtype(uri.fromfile(response),
                "application/vnd.android.package-archive");
            startactivityforresult(intent, 0);
          }
        });
  }

以上所述是小编给大家介绍的android okhttputils现在进度显示实例代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网