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现在进度显示实例代码,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
荐 面试官:kafka日志段如何读写都不知道,好意思说精通Kafka吗?
荐 如何写出一份“有理有据使人信服”的Android项目设计文档
荐 灵魂一问,Android中有代替HashMap的方法吗?
intent.setFlag的参数 FLAG_ACTIVITY_CLEAR_TASK 说明
网友评论