CronetProviderInstaller

public class CronetProviderInstaller extends Object

A utility class to facilitate using Cronet from Google Play services.

For more information about Cronet, refer to the developer documentation.

Use this class to load the implementation of Cronet shipped with Google Play services instead of packaging the Cronet native library with your apps. Using this implementation of Cronet, you can significantly reduce the size of your APKs, as well as get security updates, bug fixes, and performance improvements automatically with updates to Google Play services.

Install the provider by calling installProvider(Context), which returns a Task. If the Task completes successfully the provider is installed; otherwise, the Task will contain one of the following errors:

  • Recoverable error: A user interaction is required to install the provider (for example, the device needs an updated version of Google Play services). Your app can invoke the provided Intent to trigger the user interaction.
  • Unrecoverable error: The Cronet Google Play Services Provider is not available. You can package an alternative fallback Cronet implementation with the APK so that your app can function even if Google Play services isn't available on the user's device.

Constant Summary

String PROVIDER_NAME The name of the provider.

Public Method Summary

static Task<Void>
installProvider(Context context)
Installs Cronet provider if it is not already installed.
static boolean
isInstalled()
Checks whether the Cronet provider is already installed.

Inherited Method Summary

Constants

public static final String PROVIDER_NAME

The name of the provider.

Constant Value: "Google-Play-Services-Cronet-Provider"

Public Methods

public static Task<Void> installProvider (Context context)

Installs Cronet provider if it is not already installed.

This method returns a Task object with no data associated with it. If the task completes successfully, the Cronet provider has been successfully installed and will be used when org.chromium.net.CronetEngine.Builder(Context) constructor is called. In case of an error, the Task will contain the corresponding exception, which can be:

If the provider is already installed, this method immediately returns a successfully completed Task with a guarantee that the first call to isSuccessful() will return true.

Use this method to install the provider asynchronously or synchronously. For the asynchronous behavior, the caller can add the corresponding Task listeners to be notified asynchronously when the result is available. For the synchronous behavior, the caller can call Tasks.await(...) to block and wait until the result is available. Note that Tasks.await(...) must not be called on the main thread.

public static boolean isInstalled ()

Checks whether the Cronet provider is already installed.

Returns
  • true if the provider is already installed.