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.
AriaLyy
1cdd216d8f
|
9 years ago | |
---|---|---|
.idea | 9 years ago | |
app | 9 years ago | |
downloadutil | 9 years ago | |
gradle/wrapper | 9 years ago | |
img | 9 years ago | |
.gitignore | 9 years ago | |
README.md | 9 years ago | |
build.gradle | 9 years ago | |
gradle.properties | 9 years ago | |
gradlew | 9 years ago | |
gradlew.bat | 9 years ago | |
settings.gradle | 9 years ago |
README.md
DownloadUtil
这是android 文件下载工具类,实现了多线程断点续传功能
#使用
DownloadUtil mUtil;
/**
* 初始化下载工具类
*/
private void init(){
mUtil = new DownloadUtile();
}
private void download(){
mUtil.download(this, mDownloadUrl, Environment.getExternalStorageDirectory().getPath() + "/test.apk"
, new DownloadListener() {
long fileSize = 1;
@Override
public void onPreDownload(HttpURLConnection connection) {
super.onPreDownload(connection);
mPb.setMax(100);
fileSize = connection.getContentLength();
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, fileSize).sendToTarget();
}
@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);
mPb.setProgress((int) (currentLocation * 100 / fileSize));
}
@Override
public void onStop(long stopLocation) {
super.onStop(stopLocation);
mUpdateHandler.obtainMessage(DOWNLOAD_STOP).sendToTarget();
}
@Override
public void onCancel() {
super.onCancel();
mUpdateHandler.obtainMessage(DOWNLOAD_CANCEL).sendToTarget();
}
@Override
public void onResume(long resumeLocation) {
super.onResume(resumeLocation);
mUpdateHandler.obtainMessage(DOWNLOAD_RESUME, resumeLocation).sendToTarget();
}
@Override
public void onFail() {
super.onFail();
mUpdateHandler.obtainMessage(DOWNLOAD_FAILE).sendToTarget();
}
@Override
public void onComplete() {
super.onComplete();
mUpdateHandler.obtainMessage(DOWNLOAD_COMPLETE).sendToTarget();
}
});
}
#下载