All Projects → smanikandan14 → Thindownloadmanager

smanikandan14 / Thindownloadmanager

Licence: apache-2.0
To download files and to avoid using DOWNLOAD_WITHOUT_NOTIFICATION permission if you are using Android's DownloadManager in your apps.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Thindownloadmanager

Updater
基于DownloadManager封装的更新器,使用超简单!
Stars: ✭ 82 (-89.24%)
Mutual labels:  downloadmanager
Hwifiledownload
HWIFileDownload simplifies file download with NSURLSession on iOS.
Stars: ✭ 209 (-72.57%)
Mutual labels:  downloadmanager
VandaDownloader
强大的下载特性支持,更加清晰的特性设计。
Stars: ✭ 25 (-96.72%)
Mutual labels:  downloadmanager
Rxdownloader
An Rx wrapper for Download Manager in Android
Stars: ✭ 107 (-85.96%)
Mutual labels:  downloadmanager
Rxdownloader
Demo of Downloading Songs/Images through Android Download Manager using RxJava2
Stars: ✭ 166 (-78.22%)
Mutual labels:  downloadmanager
scihub
Copernicus Sentinel Science Hub rolling archive downloader
Stars: ✭ 28 (-96.33%)
Mutual labels:  downloadmanager
Fetch
The best file downloader library for Android
Stars: ✭ 1,124 (+47.51%)
Mutual labels:  downloadmanager
Androiddownloader
An powerful download library for Android.
Stars: ✭ 287 (-62.34%)
Mutual labels:  downloadmanager
Pyload
The free and open-source Download Manager written in pure Python
Stars: ✭ 2,393 (+214.04%)
Mutual labels:  downloadmanager
QuietDownload
🔥下载可以很简单。单任务下载、多任务下载、暂停全部任务、自动恢复下载、断点续传、任何一个界面监听进度等
Stars: ✭ 42 (-94.49%)
Mutual labels:  downloadmanager
Android Download Manager Pro
Android/Java download manager library help you to download files in parallel mechanism in some chunks.
Stars: ✭ 1,568 (+105.77%)
Mutual labels:  downloadmanager
Psdle
Improving everyone's favorite online download list, one loop at a time.
Stars: ✭ 141 (-81.5%)
Mutual labels:  downloadmanager
android-downloader
An powerful download library for Android.
Stars: ✭ 375 (-50.79%)
Mutual labels:  downloadmanager
Docker Jdownloader
JDownloader 2 Docker Image (Multiarch) - Passed 40M Downloads
Stars: ✭ 85 (-88.85%)
Mutual labels:  downloadmanager
uget
(WIP) Universal Getter of remote files
Stars: ✭ 46 (-93.96%)
Mutual labels:  downloadmanager
Uget Chrome Wrapper
Moved to https://github.com/ugetdm/uget-integrator and https://github.com/ugetdm/uget-extension
Stars: ✭ 74 (-90.29%)
Mutual labels:  downloadmanager
DownloadManagerPlus
Using faster and easier than Android Download Manager
Stars: ✭ 80 (-89.5%)
Mutual labels:  downloadmanager
Fast Android Networking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
Stars: ✭ 5,346 (+601.57%)
Mutual labels:  downloadmanager
dl
Command-line file downloader tool
Stars: ✭ 39 (-94.88%)
Mutual labels:  downloadmanager
electron-download-manager
Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading
Stars: ✭ 113 (-85.17%)
Mutual labels:  downloadmanager

ThinDownloadManager

Thin DownloadManager is an android library primary to download files and to avoid using DOWNLOAD_WITHOUT_NOTIFICATION permission when using Android provided DownloadManager in your application.

Why ?

There are few reasons why you might want to use this library.

  • There are situations where you wanted to download a file into application's sandboxed cache or files directory where no one else can access to. DownloadManager provided by android does not have facility to download directly to application's cache or files directory (/data/data//cache/ or /data/data//files/). It can only accept destination in external SDcard as download destination. And if you are not using application's external file directory as destination i.e (setDestinationInExternalFilesDir()) you have to have android.permission.WRITE_EXTERNAL_STORAGE

Most of the times we download using Android's DownloadManager to external files directory and upon successful completion move the downloaded file to the sandboxed application's cache/file directory to avoid writing a own download manager which is a bit tedious. This library is handy in such situations.

  • No additional permissions required. Any download initiated by your application using android DownloadManager would throw a progress notification on status bar letting user know that you are downloading a file. So you end up using setVisibleInDownloadsUi(false) & having this permission android.permission.DOWNLOAD_WITHOUT_NOTIFICATION. When users install your app, they would be shown this permission and it makes them scary not to install your app because you are downloading some files without user's notification. Why give a chance of user not installing your app for this permission. You definetly need this library in this case.

  • Volley - Google recommended Networking library for android doesn't have options to download a file.

Usuage

DownloadStatusListener (Deprecated)

  • Provides call back option to know when the download is completed, failed and reason for failure, and to know the progress of the download.
    //Callback when download is successfully completed
    void onDownloadComplete (int id);

    //Callback if download is failed. Corresponding error code and
    //error messages are provided
    void onDownloadFailed (int id, int errorCode, String errorMessage);

    //Callback provides download progress
    void onProgress (int id, long totalBytes, long downlaodedBytes, int progress);

DownloadStatusListenerV1

  • Provides call back option to know when the download is completed, failed and reason for failure, and to know the progress of the download. DownloadRequest is given back in the callback so that you can easily set some Object as context to download request and get the context object back from the request object.
    //Callback when download is successfully completed
    void onDownloadComplete(DownloadRequest downloadRequest);

    //Callback if download is failed. Corresponding error code and
    //error messages are provided
    void onDownloadFailed(DownloadRequest downloadRequest, int errorCode, String errorMessage);


    //Callback provides download progress
    void onProgress(DownloadRequest downloadRequest, long totalBytes, long downloadedBytes, int progress);

DownloadRequest

  • Takes all the necessary information required for download.

  • Download URI, Destination URI.

  • Set Priority for request as HIGH or MEDIUM or LOW.

  • Takes Callback listener DownloadStatusListener

  • Use custom Http Headers for a download request

  • Resumable a download if network connection drops or download is paused.

  • You can set a Retry Policy

       Uri downloadUri = Uri.parse("http://tcrn.ch/Yu1Ooo1");
       Uri destinationUri = Uri.parse(this.getExternalCacheDir().toString()+"/test.mp4");
       DownloadRequest downloadRequest = new DownloadRequest(downloadUri)
               .addCustomHeader("Auth-Token", "YourTokenApiKey")
               .setRetryPolicy(new DefaultRetryPolicy())
               .setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH)
               .setDownloadContext(downloadContextObject)//Optional
               .setDownloadListener(new DownloadStatusListener() {
                   @Override
                   public void onDownloadComplete(int id) {
    
                   }
    
                   @Override
                   public void onDownloadFailed(int id, int errorCode, String errorMessage) {
    
                   }
    
                   @Override
                   public void onProgress(int id, long totalBytes, long downlaodedBytes, int progress)) {
    
                   }
               });
    
    

ThinDownloadManager

  • The number of threads used to perform parallel download is determined by the available processors on the device. Uses Runtime.getRuntime().availableProcessors() api.

    private ThinDownloadManager downloadManager;
    .....
    
    downloadManager = new ThinDownloadManager();
    
    .... 
    
  • To start a download use add( DownloadRequest request)

    int downloadId = downloadManager.add(downloadRequest);
    
  • To cancel a particular download use cancel(int downloadId) by passing download id.

    • Returns 1 if successfull cancelled.
    • Returns -1 if supplied download id is not found.
    int status = downloadManager.cancel(downloadId);
    
  • To cancel all running requests use cancelAll()

    downloadManager.cancelAll();
    
  • To query for a particular download use query(int downloadId)

    The possible status could be

    • STATUS_PENDING
    • STATUS_STARTED
    • STATUS_RUNNING
    int status = downloadManager.query(downloadId);
    
  • To pause a download in progress. The download request has to be marked as setDownloadResumable to true

    downloadManager.pause(downloadId)
    
  • To release all the resources used by download manager use release().

    downloadManager.release();
    

No Permissions Required

  • Unless if you specify download destination to be in external public SDCard location.You might need android.permission.WRITE_EXTERNAL_STORAGE permission.

Setup

Include below line your build.gradle:

dependencies {
    compile 'com.mani:ThinDownloadManager:1.4.0'
}

Make sure you included jcenter() in your repositories section.

Download

  • The source code of sample app code is available for you to play around and the app itself is available for download from play store :

Get it on Google Play

  • Sample app demonstrates with 4 thread pool size and download three different formats of files jpg, mp3, mp4.
  • The files are downloaded to applications sandboxed files directory. */data/data//files.

Android Arsenal

Credits

https://android.googlesource.com/platform/packages/providers/DownloadProvider/

NOTE: Android's DownloadManager has plenty of features which is not available in ThinDownloadManager. For ex. pause and continue download when network connectivity changes.So analyse your requirement thoroughly and decide which one to use.

https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/ Steps for uploading to bintray.

License

 Copyright 2013 Mani Selvaraj

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].