0

我使用 OKHTTP3 库下载文件,然后使用 Okio.buffer 将文件保存到磁盘,但我想在连续下载时显示进度条,我该如何使用 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();
        }
4

0 回答 0