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現在進度顯示實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答