-
Notifications
You must be signed in to change notification settings - Fork 773
Advanced Use Guideline
Jacksgong edited this page May 7, 2018
·
15 revisions
OkDownload.with().setMonitor(monitor);
DownloadDispatcher.setMaxParallelRunningCount(3);
RemitStoreOnSQLite.setRemitToDBDelayMillis(3000);
OkDownload.with().downloadDispatcher().cancelAll();
OkDownload.with().breakpointStore().remove(taskId);
If you want to inject your components, please invoke following method before you using OkDownload:
OkDownload.Builder builder = new OkDownload.Builder(context)
.downloadStore(downloadStore)
.callbackDispatcher(callbackDispatcher)
.downloadDispatcher(downloadDispatcher)
.connectionFactory(connectionFactory)
.outputStreamFactory(outputStreamFactory)
.downloadStrategy(downloadStrategy)
.processFileStrategy(processFileStrategy)
.monitor(monitor);
OkDownload.setSingletonInstance(builder.build());
DownloadSerialQueue serialQueue = new DownloadSerialQueue(commonListener);
serialQueue.enqueue(task1);
serialQueue.enqueue(task2);
serialQueue.pause();
serialQueue.resume();
int workingTaskId = serialQueue.getWorkingTaskId();
int waitingTaskCount = serialQueue.getWaitingTaskCount();
DownloadTask[] discardTasks = serialQueue.shutdown();
DownloadListener listener1 = new DownloadListener1();
DownloadListener listener2 = new DownloadListener2();
DownloadListener combinedListener = new DownloadListenerBunch.Builder()
.append(listener1)
.append(listener2)
.build();
DownloadTask task = new DownloadTask.build(url, file).build();
task.enqueue(combinedListener);
// all attach or detach is based on the id of Task in fact.
UnifiedListenerManager manager = new UnifiedListenerManager();
DownloadListener listener1 = new DownloadListener1();
DownloadListener listener2 = new DownloadListener2();
DownloadListener listener3 = new DownloadListener3();
DownloadListener listener4 = new DownloadListener4();
DownloadTask task = new DownloadTask.build(url, file).build();
manager.attachListener(task, listener1);
manager.attachListener(task, listener2);
manager.detachListener(task, listener2);
// all listeners added for this task will be removed when task is end.
manager.addAutoRemoveListenersWhenTaskEnd(task.getId());
// enqueue task to start.
manager.enqueueTaskWithUnifiedListener(task, listener3);
manager.attachListener(task, listener4);
DownloadTask.Builder builder = new DownloadTask.Builder(url, file);
// Set the minimum internal milliseconds of progress callbacks to 100ms.(default is 3000)
builder.setMinIntervalMillisCallbackProcess(100);
// set the priority of the task to 10, higher means less time to wait to download.(default is 0)
builder.setPriority(10);
// set the read buffer to 8192 bytes for the response input-stream.(default is 4096)
builder.setReadBufferSize(8192);
// set the flush buffer to 32768 bytes for the buffered output-stream.(default is 16384)
builder.setFlushBufferSize(32768);
// set this task allow using 5 connections to download data.
builder.setConnectionCount(5);
// build the task.
DownloadTask task = builder.build();
If there are some special url need to be downloaded please move to here.