Retrofit: How to set listener for downloading progress?

Created on 23 Sep 2015  路  7Comments  路  Source: square/retrofit

I can't find API to call get progress function when download a file by retrofit ,How can i implement this function?

Most helpful comment

All 7 comments

Here's an OkHttp recipe showing how to do it in an interceptor: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/com/squareup/okhttp/recipes/Progress.java. If you want to do it for a single call you'd need to use ResponseBody as your response type and then immediately wrap it with the ProgressResponseBody from that code snippet before you read.

Very glad that you can reply to me, for that matter, I have the answer, thanks!

Where exactly should I wrap with the ProgressResponseBody?

After I make the call.enqueue()??

@JakeWharton Is this at all possible without an interceptor? How to get ResponseBody from a Call object before calling execute() or enqueue() ?

@JakeWharton For Progress for RequestBody, how should writeTo() be implemented - if this is the one to modify from the recipe?

@JakeWharton Is this at all possible without an interceptor? How to get ResponseBody from a Call object before calling execute() or enqueue() ?

Was this page helpful?
0 / 5 - 0 ratings