Multi-thread & Multi-task downloading library for Android projects.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4f711ba Feb 23, 2015
Failed to load latest commit information.
library update to v1.1.0 Feb 9, 2015
.gitignore Initial commit Nov 9, 2014
LICENSE Initial commit Nov 9, 2014 Update Feb 23, 2015


Multi-thread & Multi-task downloading library for Android projects.

Todo List:

  • Multi-thread downloading. √
  • Broken-point continuingly-transferring support. √
  • Callback interfaces. √
  • Handling Exceptions. √
  • Multi-task management. √
  • Synchronized communication between threads. ×

What's new in v1.1.0?

  • Multi-task Manager: Helps you manage tasks efficiently.
  • Optimized code structure.

How to update to v1.1.0?

Because the code structure is changed, you must update your code in order to use the new version library.

  • Change imported package name: →

  • Change listener: DownloadProgressListener → DownloadCallbacks

  • DownloadCallbacks return a String taskId in each callback method.

  • If you still want to use single task downloader, the DownloadTask is located in package:

  • If you want to try out the new Multi-task Manager, find your way in usage section. :)

Known bug

Too many threads might cause unpredictable exceptions such as losing track of threads or even worse.

  • Please keep the number of your download threads less than eight(five is recommended).


  • If you initialized the DownloadTask/Multi-task Manager in an Activity, you will lose communication with downloading tasks after the Activity destroied.

To solve this issue, we recommend you to create a List (or create Multi-task Manager in Service) to save these instances inside.


Permissions Requirement

Declare these permissions in Manifest first.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Multi-task Manager Ver.:
  • Get instance
MultiTaskManager mtm = new MultiTaskManager(context, new DownloadCallbacks(){
 		public void onDownloadProgress(String taskId, int size)
 			// TODO: Implement this method
	 	public void onDownloadException(String taskId, Exception e)
	 		// TODO: Implement this method
		public void onDownloadFinish(String taskId)
 			// TODO: Implement this method
 		public void onDownloadStart(String taskId, int size)
 			// TODO: Implement this method
  • API:Set default download path
public void setDefaultPath(File path);
  • API:New task
public String newTask(String dlUrl, File savDir, int threadNum, boolean startImmediately);

If you have set a default download path, you can use the code below to add new tasks.

public String newTask(String dlUrl, int threadNum, boolean startImmediately);
    • Parameters

    • dlUrl: Url to download file from.

    • savDir: Where should downloaded file save to.(This can be ignored when a default download path is set.)

    • threadNum: How many threads will be used for download.

    • startImmediately: If true, task will start automatically after added.

This method will return a String taskId, you can use taskId to manage a single task.

  • Manage a single task.
//Start a task
public void start(String taskId);
//Resume a task
public void resume(String taskId);
//Suspend a task
public void start(String taskId);
//Terminate a task
public void start(String taskId);

All method called from Multi-task Manager need to be surrounded in try/catch block. You can get all detailed exception information using exception.getMessage().

Single task Ver.:
  • Get instance
DownloadTask task = new DownloadTask(this, dlUrl, savDir, threads, new DownloadProgressListener(){
	public void onDownloadStart(int length)
		//Call when download is started.
		Log.i("[dpl_callback]", "------download started!");
		Log.i("[dpl_callback]", "------file length:" + length);
	public void onDownloadFinish()
		//Call when download is finished.
		Log.i("[dpl_callback]", "------download finished!");
	public void onDownloadError(Exception e)
		//Call when an exception is thrown.
		Log.e("[dpl_callback]", "------download error:" + e.getMessage());
	public void onDownloadProgress(int size)
		//Call when download progress is changed.
		Log.i("[dpl_callback]", "------downloaded size:" + size);

Examples below are for single task management.

  • Start download
new Thread(task).start();

NOTICE: You can get the total size of the file inside the callback interface "onDownloadStart(int size)".

  • Pause
  • Resume

Same as starting a new download task. You can also use an exist instance to resume downloading progress.

new Thread(task).start();

If you had already TERMINATED the task, downloading will start from scratch.

  • Terminate

Download Sample APK(Old version)

Copyright(c)2014-2015 Sumi Makito.
Licensed under GNU GPL v3. Read License.
About myself: