一个用于下载的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
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2303
- 用户1336
- 访客11129740
每日一句
Just hold to your dream and never give up.
坚持你的梦想,永不放弃。
坚持你的梦想,永不放弃。
【教程】win10 彻底卸载edge浏览器
Node.js框架之Egg.js
iOS项目允许使用http协议请求
Cocos2d-x 3.17.2和Android Studio环境搭建
鸿蒙Failure[INSTALL_PARSE_FAILED_USESDK_ERROR]
java.nio.ByteBuffer缓冲区简介
linux下C/C++网络编程基本:socket实现tcp和udp的例子
CreateProcessW要注意的细节问题
C/C++通过WMI和系统API函数获取系统硬件配置信息
Xposed框架的使用
Android自定义蜂窝布局
Java开发人员的7种最佳测试框架
C++11特性里面的thread
新会员