Android okhttputils现在进度显示实例代码
2019/7/7 21:04:35
本文主要是介绍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现在进度显示实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对找一找教程网网站的支持!
这篇关于Android okhttputils现在进度显示实例代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路