一个用于下载的android库。
主要特性如下:
1、使用简单,只需要下载地址即可;
2、可以猜测下载任务名称
3、自动设置下载路径
4、支持断点续传
5、所有监听返回的接口,例如onAdd等,都支持UI操作
权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用例子:
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()");
}
};
收藏的用户(0) X
正在加载信息~
推荐阅读
Android Studio开发之app:transformJackWithJackForDebug错误
最新回复 (0)
站点信息
- 文章2313
- 用户1336
- 访客11756754
每日一句
Life is short; Live it!
人生苦短,活出精彩。
人生苦短,活出精彩。
信鸽推送报错NSObject checkTargetOtherLinkFlagForObjc
简单利用Clover四叶草安装U盘安装黑苹果
学习使用Java注解
OllyDbg中如何找出B模块中所有调用了A模块的C方法的地方
解决SSH客户端中文乱码
10年后,Android应用程序仍然比iOS应用程序差
C++11特性里面的thread
XPosed微信自动生成二维码
解决android studio "found an invalid color"的问题
T9社区注册方法【勼适様鲃女尔懟死】
Thinkpad x1 Extreme黑苹果10.14.5安装完成
基于大白主题增加图片本地化的功能
Linux系统查看CPU使用率的几个命令
新会员
