public final class CronetUtil


Cronet utility methods.

Summary

Public methods

static @Nullable CronetEngine

Builds a CronetEngine suitable for use with CronetDataSource.

static @Nullable CronetEngine
@UnstableApi
buildCronetEngine(
    Context context,
    @Nullable String userAgent,
    boolean preferGooglePlayServices
)

Builds a CronetEngine suitable for use with CronetDataSource.

Public methods

buildCronetEngine

public static @Nullable CronetEngine buildCronetEngine(Context context)

Builds a CronetEngine suitable for use with CronetDataSource. When choosing a Cronet provider to build the CronetEngine, disabled providers are not considered. Neither are fallback providers, since it's more efficient to use than it is to use CronetDataSource with a fallback .

Note that it's recommended for applications to create only one instance of , so if your application already has an instance for performing other networking, then that instance should be used and calling this method is unnecessary. See the Android developer guide to learn more about using Cronet for network operations.

Parameters
Context context

A context.

Returns
@Nullable CronetEngine

The CronetEngine, or null if no suitable engine could be built.

buildCronetEngine

@UnstableApi
public static @Nullable CronetEngine buildCronetEngine(
    Context context,
    @Nullable String userAgent,
    boolean preferGooglePlayServices
)

Builds a CronetEngine suitable for use with CronetDataSource. When choosing a Cronet provider to build the CronetEngine, disabled providers are not considered. Neither are fallback providers, since it's more efficient to use than it is to use CronetDataSource with a fallback .

Note that it's recommended for applications to create only one instance of , so if your application already has an instance for performing other networking, then that instance should be used and calling this method is unnecessary. See the Android developer guide to learn more about using Cronet for network operations.

Parameters
Context context

A context.

@Nullable String userAgent

A default user agent, or null to use a default user agent of the CronetEngine.

boolean preferGooglePlayServices

Whether Cronet from Google Play Services should be preferred over Cronet Embedded, if both are available.

Returns
@Nullable CronetEngine

The CronetEngine, or null if no suitable engine could be built.