You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Android-Download/README.md

133 lines
4.0 KiB

9 years ago
# DownloadUtil
9 years ago
这是android 文件下载工具类,实现了多线程断点续传功能</br>
如果你觉得我的代码对你有帮助,请麻烦你在右上角给我一个star.^_^
9 years ago
9 years ago
#下载
[![Download](https://api.bintray.com/packages/arialyy/maven/MTDownloadUtil/images/download.svg)](https://bintray.com/arialyy/maven/MTDownloadUtil/_latestVersion)<br/>
9 years ago
compile 'com.arialyy.downloadutil:DownloadUtil:1.0.2'
9 years ago
9 years ago
#使用
```java
DownloadUtil mUtil;
/**
* 初始化下载工具类
*/
private void init(){
mUtil = new DownloadUtile();
}
9 years ago
/**
* 开始下载和恢复下载都是这个..
*/
private void download(){
9 years ago
mUtil.download(this, mDownloadUrl, Environment.getExternalStorageDirectory().getPath() + "/test.apk"
9 years ago
, new DownLoadUtil.DownloadListener() {
9 years ago
long fileSize = 1;
@Override
public void onPreDownload(HttpURLConnection connection) {
super.onPreDownload(connection);
9 years ago
//在这里编写下载预处理操作
9 years ago
fileSize = connection.getContentLength();
}
@Override
public void onStart(long startLocation) {
super.onStart(startLocation);
9 years ago
//在这里编写开始后的相应操作
9 years ago
}
@Override
public void onChildResume(long resumeLocation) {
super.onChildResume(resumeLocation);
9 years ago
//子线程恢复下载的位置回调
9 years ago
}
@Override
public void onChildComplete(long finishLocation) {
super.onChildComplete(finishLocation);
9 years ago
//子线程完成下载的回调
9 years ago
}
@Override
public void onProgress(long currentLocation) {
super.onProgress(currentLocation);
9 years ago
//下载总进度回调
9 years ago
}
@Override
public void onStop(long stopLocation) {
super.onStop(stopLocation);
9 years ago
//停止下载的回调
9 years ago
}
@Override
public void onCancel() {
super.onCancel();
9 years ago
//取消下载回调
9 years ago
}
@Override
public void onResume(long resumeLocation) {
super.onResume(resumeLocation);
9 years ago
//恢复下载回调
9 years ago
}
@Override
public void onFail() {
super.onFail();
9 years ago
//下载失败回调
9 years ago
}
@Override
public void onComplete() {
super.onComplete();
9 years ago
//下载完成回调
9 years ago
}
});
9 years ago
}
/**
* 停止下载
*/
private void stopDownload(){
if(mUtil != null){
mUtil.stopDownload();
}
}
/**
* 取消下载
*/
private void cancelDownload(){
if(mUtil != null){
mUtil.cancelDownload();
}
}
9 years ago
```
#示例
![例子图](https://github.com/AriaLyy/DownloadUtil/blob/master/img/11.gif "")
9 years ago
License
-------
Copyright 2016 AriaLyy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.