UrlRequestCallbacks

public class UrlRequestCallbacks


Utility class for creating simple, convenient UrlRequest.Callback implementations for reading common types of responses.

Note that the convenience callbacks store the entire response body in memory. We do not recommend using them if it's possible to stream the response body, or if the response body sizes can cause strain on the on-device resources.

The helper callbacks come in two flavors - either the caller provides a callback to be invoked when the request finishes (successfully or not), or the caller is given a Future which completes when Cronet finishes processing the request.

Summary

Nested types

public class UrlRequestCallbacks.CallbackAndResponseFuturePair<ResponseBodyT, CallbackT extends InMemoryTransformCronetCallback<ResponseBodyT>>

A named pair-like structure encapsulating Cronet callbacks and associated response futures.

Public methods

forByteArrayBody

public static ByteArrayCronetCallback forByteArrayBody(
    RedirectHandler redirectHandler,
    CronetRequestCompletionListener<byte[]> listener
)

forJsonBody

public static JsonCronetCallback forJsonBody(
    RedirectHandler redirectHandler,
    CronetRequestCompletionListener<JSONObject> listener
)

forStringBody

public static StringCronetCallback forStringBody(
    RedirectHandler redirectHandler,
    CronetRequestCompletionListener<String> listener
)