我使用OKHTTP3库下载文件,然后使用Okio.buffer将文件保存到磁盘,但是我想在连续下载时显示progressBar,如何用Okio做到这一点?
try {
okhttp3.Response response = client.newCall(request).execute();
ResponseBody body = response.body();
if(response.isSuccessful()) {
Log.i("body", "" + body);
File destFilePath = Utils.getDestFilePath(context,fileNameList.get(i));
File downloadedFile = new File(destFilePath, fileNameList.get(i));
BufferedSink sink = Okio.buffer(Okio.sink(downloadedFile));
sink.writeAll(response.body().source());
sink.close();
downloadingFileSize++;
if(fileNameList.get(i).equals("imageContent.zip")) {
String source = destFilePath + "/" + fileNameList.get(i);
String target = destFilePath.getAbsolutePath();
Utils.unzip(source, target);
}else if(fileNameList.get(i).equals("videoContent.zip")){
String source = destFilePath + "/" + fileNameList.get(i);
String target =destFilePath.getAbsolutePath();
Utils.unzip(source, target);
}else if(fileNameList.get(i).equals("Widget")) {
String source = destFilePath + "/" + fileNameList.get(i);
String target = destFilePath.getAbsolutePath();
Utils.unzip(source, target);
}
}
} catch (IOException e) {
e.printStackTrace();
}