导入依赖:
implementation 'com.lzy.net:okgo:3.0.4'
之后就是OkGo的最简单的格式了:
OkGo.<File>get("https://pic.baike.soso.com/ugc/baikepic2/0/ori-20190627170527-550355963_jpg_430_515_17616.jpg/800").execute(new FileCallback("/sdcard"//下载文件路径
,"123456.jpg"//下载文件名称
) {
@Override
public void onSuccess(Response<File> response) {
File body = response.body();
}
@Override
public void downloadProgress(Progress progress) {
float fraction = progress.fraction; //0-1 之间的一个数
bar.setProgress((int) (fraction*100));//用于进度条
System.out.println("===================="+fraction);
super.downloadProgress(progress);
}
});