Okhttp: How to get the download progress

Created on 18 Apr 2015  Â·  8Comments  Â·  Source: square/okhttp

How to get the download progress

When I want to download pictures to show the progress bar

Most helpful comment

All 8 comments

Request.Builder requestBuilder = new Request.Builder()
.url(url.toStringUrl());
for (Map.Entry 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());
    }

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

@NightlyNexus awsome! thx for your reply!

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 ?

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

this is multi-file downloader with progress.

Was this page helpful?
0 / 5 - 0 ratings