明薇通网站建设价格,深圳做网站哪里好,四川省住房和城乡建设厅厅长,慕课网电子商务网站开发为什么80%的码农都做不了架构师#xff1f; ion是的一个安卓异步网络和图片加载库。 特性 异步下载#xff1a;下载图片 (用ImageViews 或者 Bitmaps显示)#xff1b;下载JSON文件 (通过Gson解析)#xff1b;下载字符串#xff1b;下载文件#xff1b;Flu… 为什么80%的码农都做不了架构师 ion是的一个安卓异步网络和图片加载库。 特性 异步下载下载图片 (用ImageViews 或者 Bitmaps显示)下载JSON文件 (通过Gson解析)下载字符串下载文件Fluent API当呼叫活动calling Activity结束时可以自动取消网络操作。所有的操作都返回一个Futurehttp://en.wikipedia.org/wiki/Futures_and_promises并且可以取消HTTP POST/PUT缓存Gzip/Deflate 压缩当有多个IP地址时自动选择最好最稳定的服务器连接 9. 支持Cookies 等等。Github 项目地址为 ion github Eclipse jar包导入形式 需要使用到两个jar 分别为 androidasync.jar 和 Ion.jar 个人测试 下载文件部分代码如下 public static void NewDownload(RequestParams params,final Context mcontext,final BaseInfo t){progressBar new ProgressBar(mcontext);progressDialog new ProgressDialog(mcontext);LogCat.i(Constants.getLogTag(), Constants.getRequestHost()t.getDownloadUrl());final NotificationManager nm (NotificationManager) mcontext.getSystemService(Context.NOTIFICATION_SERVICE);final Notification.Builder builder new Notification.Builder(mcontext);builder.setWhen(System.currentTimeMillis()).setContentTitle(t.getName() 下载中).setContentText(t.getVersionName());builder.setLargeIcon(bitmap);builder.setSmallIcon(R.drawable.download_icon);File file Environment.getExternalStorageDirectory();File file2 new File(file, down);file2.mkdir();file2 new File(file2,t.getName() .apk);Ion.with(mcontext).load(Constants.getRequestHost()t.getDownloadUrl()).progressBar(progressBar).progressDialog(progressDialog).progress( new ProgressCallback() {Overridepublic void onProgress( long downloaded, long total) {builder.setProgress(( int)(total/(1024*1024)), (int)downloaded/(1024*1024), false);builder.setContentText(downloaded/(1024*1024) .downloaded%(1024*1024) M / (total/(1024*1024)).(total%(1024*1024))M );Intent intent new Intent(mcontext,DownloadingActivity.class );Bundle bundle new Bundle();bundle.putLong( downloaded, downloaded);bundle.putLong( total, total);bundle.putSerializable( appInfo, t);intent.putExtras(bundle);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);PendingIntent pendintent PendingIntent.getActivity(mcontext, Notification_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);builder.setContentIntent(pendintent);Notification notification builder.getNotification();nm.notify(Notification_id, notification);}}).write(file2).setCallback( new FutureCallbackFile() {Overridepublic void onCompleted(Exception e, File file) {if (e null) {AppUtil.install(mcontext, Environment.getExternalStorageDirectory()File.separatordown File.separatort.getName().apk);nm.cancel(Notification_id);} else{Utils.showToast(mcontext, 下载失败请稍后重试 );nm.cancel(Notification_id);}}});} 根据请求使用Notification的形式动态展示 当前下载进度展示并设定了 PendingIntent 点击Notification时跳转特定页面并展示当前下载进度。 转载于:https://my.oschina.net/leov1/blog/506451