okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

How to get the download progress

Open libanghui opened this issue 11 years ago • 8 comments

How to get the download progress

When I want to download pictures to show the progress bar

libanghui avatar Apr 18 '15 15:04 libanghui

Request.Builder requestBuilder = new Request.Builder() .url(url.toStringUrl()); for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) { requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue()); } Request request = requestBuilder.build();

    Response response = client.newCall(request).execute();
    responseBody = response.body();
    if (!response.isSuccessful()) {
        throw new IOException("Request failed with code: " + response.code());
    }

libanghui avatar Apr 18 '15 16:04 libanghui

There is a progress recipe here: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/com/squareup/okhttp/recipes/Progress.java

JakeWharton avatar Apr 18 '15 16:04 JakeWharton

Hi, @JakeWharton, the url you provide here is closed...

huanzhiyazi avatar Feb 03 '16 10:02 huanzhiyazi

@huanzhiyazi The package name changed. :) updated: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java

NightlyNexus avatar Feb 03 '16 19:02 NightlyNexus

@NightlyNexus awsome! thx for your reply!

huanzhiyazi avatar Feb 04 '16 09:02 huanzhiyazi

Hi , @JakeWharton , i can download a file successfully and get the correct progress well . but i am confused that, it means clone a new OkHttpClient instance and set a new ProgressListener for every request , if i want to download multi file and get these progress simultaneously ?

I don't understand my idea is correct or not,or there is other way to implement that download multi file and get progress ?

ThatRoy avatar Jan 15 '18 13:01 ThatRoy

hi, @WalkingRoy i' v got the same issue ( i must show the progress of multiple request) did you resolve it ??

khalilsam avatar Jun 21 '18 09:06 khalilsam

this is multi-file downloader with progress.

anastr avatar Jun 15 '20 11:06 anastr