打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android Ion 框架 文件下载
 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() {                 @Override                 public 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 FutureCallback<File>() {                                 @Override                 public void onCompleted(Exception e, File file) {                      if (e == null) {                           AppUtil.install(mcontext, Environment.getExternalStorageDirectory()+File.separator+"down" +File.separator+t.getName()+".apk");                           nm.cancel(Notification_id);                     } else{                           Utils.showToast(mcontext, "下载失败,请稍后重试" );                           nm.cancel(Notification_id);                     }                }           });     }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android Notification通知
承香墨影 Android--通知之Notification
Android 8.0 版本更新的适配
Android O(8.0)通知栏适配
全面了解Android Notification
2.5.8 Notification(状态栏通知)详解 | 菜鸟教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服