0

I downloaded file using OKHTTP3 library, and then I saved file to disk using Okio.buffer,but I want to show progressBar when downloading continously,how can I do this with 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();
        }
Diego
  • 937
  • 8
  • 24
  • 1
    You can use an OkHttp interceptor: https://github.com/commonsguy/cw-omnibus/blob/FINAL/HTTP/OkHttpProgress/app/src/main/java/com/commonsware/android/okhttp3/progress/Downloader.java – CommonsWare Dec 17 '19 at 13:19
  • 1
    Also: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java – Jesse Wilson Dec 17 '19 at 15:44

0 Answers0