How to get the download progress
When I want to download pictures to show the progress bar
Request.Builder requestBuilder = new Request.Builder()
.url(url.toStringUrl());
for (Map.Entry
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());
}
There is a progress recipe here: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/com/squareup/okhttp/recipes/Progress.java
Hi, @JakeWharton, the url you provide here is closed...
@huanzhiyazi The package name changed. :)
updated: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java
@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.
Most helpful comment
@huanzhiyazi The package name changed. :)
updated: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java