源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-03-20 07:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android okhttputils现在进度显示实例代码
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现在进度显示实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部