Android Fast Download file from server using ANDROID FAST NETWORKING LIBRARY

Librarylink:https://github.com/amitshekhariitbhu/Fast-Android-Networking

Dependency

Function()



    public String DownloadFileHandler(String fileurl,String dirPath,String localfilename)
    {
        String filename= "IMG_"+getTimestamp();
        filename=filename+Getext(fileurl);
        fullpath=dirPath+localfilename;
         OKHTTP_SSL ssl =new OKHTTP_SSL(ctx);

        AndroidNetworking.download(fileurl,dirPath,localfilename)
        .setTag("downloadTest")
        .setPriority(Priority.HIGH)
        .setOkHttpClient(ssl.Okhttpclient())
        .setPercentageThresholdForCancelling(50) // even if at the time of cancelling it will not cancel if 50%
        .build()                                 // downloading is done.But can be cancalled with forceCancel.
        .setDownloadProgressListener(new DownloadProgressListener() {
           @Override
           public void onProgress(long bytesDownloaded, long totalBytes) {
           // do anything with progress 
           }
        })
        .startDownload(new DownloadListener() {
           @Override
           public void onDownloadComplete() {
           // do anything after completion
//             
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
              
              
              
           }
           @Override
           public void onError(ANError error) {
           // handle error   
          
              
//               Toast.makeText(ctx, "Error file download"+error.toString(), Toast.LENGTH_SHORT).show();
           }
       });  






Comments