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); } } }); }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。