Ion is an Android asynchronous network and image loading library.
Characteristics
-
Asynchronous Download:
-
Fluent API;
-
When the call activity (calling activity) ends, the network operation can be automatically canceled.
-
All operations return a future (http://en.wikipedia.org/wiki/Futures_and_promises), and can be canceled;
-
HTTP Post/put;
-
Cache
-
Gzip/deflate compression
-
When there are multiple IP addresses, automatically choose the best and most stable server connection; 9. Support for cookies and so on.
The GitHub project address is: Ion GitHub
Eclipse jar Package Import form:
You need to use up to two jars, respectively: Androidasync.jar and Ion.jar
The Personal test download File section code is as follows:
public static void newdownload (Requestparams params,final context mcontext , final baseinfo t) { progressbar = new progressbar (Mcontext); Progressdialog = new progressdialog (Mcontext); &NBSP;&NBSP;&NBSP;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 () + "Download"). 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* (1024x768), 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, "Download failed, please retry later" ) ; nm.cancel (notification_id); } } } ); }
According to the request, using notification to dynamically display the current download progress display, and set the pendingintent, click Notification, jump to a specific page, and show the current download progress.
Android Ion Framework File download