您的位置:首页 > 编程语言

使用开源项目xutils实现多线程断点下载

2016-07-02 19:26 337 查看
我们在github上搜索xutils即可找到开源项目xutils,下载拷贝到项目中。地址是https://github.com/wyouflf/xUtils.git

使用开源项目xutils实现多线程断点下载,只需三步:

1. 导入下载好的xUtils.jar包;

2. 实例化一个HttpUtils对象http;

3. 调用httpdownload方法.

代码如下所示:

HttpUtils http = new HttpUtils();
http.download(path, "/mnt/sdcard/xxx.exe", true, new RequestCallBack<File>() {

@Override
public void onSuccess(ResponseInfo<File> arg0) {
Toast.makeText(MainActivity.this, "下载成功", 0).show();
}

@Override
public void onLoading(long total, long current, boolean isUploading) {
//ProgressBar进度条更新
pb0.setMax((int) total);
pb0.setProgress((int) current);
super.onLoading(total, current, isUploading);
}

@Override
public void onFailure(HttpException arg0, String arg1) {
Toast.makeText(MainActivity.this, "下载失败"+arg1, 0).show();
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息