Android Ion Framework File download

Source: Internet
Author: User

Ion is an Android asynchronous network and image loading library.

Characteristics

    • Asynchronous Download:

      • Download images (shown with imageviews or bitmaps);

      • Download the JSON file (parse by Gson);

      • Download the string;

      • Download the file;

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.