android 下载库,android下载库downloader

一个用于下载的android库。

主要特性如下:

1、使用简单,只需要下载地址即可;

2、可以猜测下载任务名称

3、自动设置下载路径

4、支持断点续传

5、所有监听返回的接口,例如onAdd等,都支持UI操作

527a9de661da1d8ef73b18078dc62dea.png

权限

使用例子:

DownloadManager downloadManager = new DownloadManager(this);

DownloadTask task = new DownloadTask(this);

task.setUrl("https://github.com/snowdream/android-autoupdate/raw/master/docs/test/android-autoupdater-v0.0.2-release.apk");

downloadManager.add(task, listener); //Add the task

downloadManager.start(task, listener); //Start the task

downloadManager.stop(task, listener); //Stop the task if you exit your APP.

private DownloadListener listener = new DownloadListener() {

/**

* The download task has been added to the sqlite.

*

* operation of UI allowed.

*

* @param downloadTask the download task which has been added to the sqlite.

*/

@Override

public void onAdd(DownloadTask downloadTask) {

super.onAdd(downloadTask);

Log.i("onAdd()");

list.add(downloadTask);

Log.i(""+downloadTask);

adapter.notifyDataSetChanged();

}

/**

* The download task has been delete from the sqlite

*

* operation of UI allowed.

*

* @param downloadTask the download task which has been deleted to the sqlite.

*/

@Override

public void onDelete(DownloadTask downloadTask) {

super.onDelete(downloadTask);

Log.i("onDelete()");

}

/**

* The download task is stop

*

* operation of UI allowed.

*

* @param downloadTask the download task which has been stopped.

*/

@Override

public void onStop(DownloadTask downloadTask) {

super.onStop(downloadTask);

Log.i("onStop()");

}

/**

* Runs on the UI thread before doInBackground(Params...).

*/

@Override

public void onStart() {

super.onStart();

Log.i("onStart()");

}

/**

* Runs on the UI thread after publishProgress(Progress...) is invoked. The

* specified values are the values passed to publishProgress(Progress...).

*

* @param values The values indicating progress.

*/

@Override

public void onProgressUpdate(Integer... values) {

super.onProgressUpdate(values);

((DownloadTaskAdapter) getListAdapter()).notifyDataSetChanged();

Log.i("onProgressUpdate");

}

/**

* Runs on the UI thread after doInBackground(Params...). The specified

* result is the value returned by doInBackground(Params...). This method

* won't be invoked if the task was cancelled.

*

* @param downloadTask The result of the operation computed by

* doInBackground(Params...).

*/

@Override

public void onSuccess(DownloadTask downloadTask) {

super.onSuccess(downloadTask);

Log.i("onSuccess()");

}

/**

* Applications should preferably override onCancelled(Object). This method

* is invoked by the default implementation of onCancelled(Object). Runs on

* the UI thread after cancel(boolean) is invoked and

* doInBackground(Object[]) has finished.

*/

@Override

public void onCancelled() {

super.onCancelled();

Log.i("onCancelled()");

}

@Override

public void onError(Throwable thr) {

super.onError(thr);

Log.i("onError()");

}

/**

* Runs on the UI thread after doInBackground(Params...) when the task is

* finished or cancelled.

*/

@Override

public void onFinish() {

super.onFinish();

Log.i("onFinish()");

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值