private void addProgressInterceptor ( ) { httpClient . networkInterceptors ( ) . add ( new Interceptor ( ) { @ Override public Response intercept ( Interceptor . Chain chain ) throws IOException { final Request request = chain . request ( ) ; final Response originalResponse = chain . proceed ( request ) ; if ( request . tag ( ) instanceof ApiCallback ) { final ApiCallback callback = ( ApiCallback ) request . tag ( ) ; return originalResponse . newBuilder ( ) . body ( new ProgressResponseBody ( originalResponse . body ( ) , callback ) ) . build ( ) ; } return originalResponse ; } } ) ; }
Add network interceptor to httpClient to track download progress for async requests .