图片
This commit is contained in:
103
README.md
103
README.md
@ -6,109 +6,6 @@
|
|||||||
[](https://bintray.com/arialyy/maven/MTDownloadUtil/_latestVersion)<br/>
|
[](https://bintray.com/arialyy/maven/MTDownloadUtil/_latestVersion)<br/>
|
||||||
compile 'com.arialyy.downloadutil:DownloadUtil:1.0.2'
|
compile 'com.arialyy.downloadutil:DownloadUtil:1.0.2'
|
||||||
|
|
||||||
#使用
|
|
||||||
```java
|
|
||||||
DownloadUtil mUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化下载工具类
|
|
||||||
*/
|
|
||||||
private void init(){
|
|
||||||
mUtil = new DownloadUtile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始下载和恢复下载都是这个..
|
|
||||||
*/
|
|
||||||
private void download(){
|
|
||||||
mUtil.download(this, mDownloadUrl, Environment.getExternalStorageDirectory().getPath() + "/test.apk"
|
|
||||||
, new DownLoadUtil.DownloadListener() {
|
|
||||||
long fileSize = 1;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPreDownload(HttpURLConnection connection) {
|
|
||||||
super.onPreDownload(connection);
|
|
||||||
//在这里编写下载预处理操作
|
|
||||||
fileSize = connection.getContentLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart(long startLocation) {
|
|
||||||
super.onStart(startLocation);
|
|
||||||
//在这里编写开始后的相应操作
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChildResume(long resumeLocation) {
|
|
||||||
super.onChildResume(resumeLocation);
|
|
||||||
//子线程恢复下载的位置回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChildComplete(long finishLocation) {
|
|
||||||
super.onChildComplete(finishLocation);
|
|
||||||
//子线程完成下载的回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProgress(long currentLocation) {
|
|
||||||
super.onProgress(currentLocation);
|
|
||||||
//下载总进度回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop(long stopLocation) {
|
|
||||||
super.onStop(stopLocation);
|
|
||||||
//停止下载的回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
super.onCancel();
|
|
||||||
//取消下载回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume(long resumeLocation) {
|
|
||||||
super.onResume(resumeLocation);
|
|
||||||
//恢复下载回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFail() {
|
|
||||||
super.onFail();
|
|
||||||
//下载失败回调
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
super.onComplete();
|
|
||||||
//下载完成回调
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 停止下载
|
|
||||||
*/
|
|
||||||
private void stopDownload(){
|
|
||||||
if(mUtil != null){
|
|
||||||
mUtil.stopDownload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消下载
|
|
||||||
*/
|
|
||||||
private void cancelDownload(){
|
|
||||||
if(mUtil != null){
|
|
||||||
mUtil.cancelDownload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
#示例
|
#示例
|
||||||

|

|
||||||
|
BIN
img/download_img.gif
Normal file
BIN
img/download_img.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 769 KiB |
Reference in New Issue
Block a user