CronetProviderInstaller
Stay organized with collections Save and categorize content based on your preferences.
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.
Public Method Summary
static Task<Void> | |
static boolean | isInstalled() Checks whether the Cronet provider is already installed. |
Inherited Method Summary
From class java.lang.Object Object | clone() |
boolean | |
void | finalize() |
final Class<?> | getClass() |
int | hashCode() |
final void | notify() |
final void | notifyAll() |
String | toString() |
final void | wait(long arg0, int arg1) |
final void | wait(long arg0) |
final void | wait() |
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eCronetProviderInstaller\u003c/code\u003e helps you use Cronet from Google Play services, reducing APK size and providing automatic updates.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the provider via \u003ccode\u003einstallProvider()\u003c/code\u003e enables Cronet to be used without bundling it with your app.\u003c/p\u003e\n"],["\u003cp\u003eIf installation fails, it could be due to a recoverable error (requiring user interaction) or an unrecoverable error (Cronet Provider unavailable).\u003c/p\u003e\n"],["\u003cp\u003eYou can check if the provider is already installed using \u003ccode\u003eisInstalled()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUsing Cronet from Google Play services offers advantages like smaller APKs, security updates, and performance improvements.\u003c/p\u003e\n"]]],[],null,["public class **CronetProviderInstaller** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nA utility class to facilitate using Cronet from Google Play services.\n\nFor more information about Cronet, refer to the [developer documentation](//developer.android.com/guide/topics/connectivity/cronet).\n\nUse this class to load the implementation of Cronet shipped with Google Play services\ninstead of packaging the Cronet native library with your apps. Using this implementation of\nCronet, you can significantly reduce the size of your APKs, as well as get security updates,\nbug fixes, and performance improvements automatically with updates to Google Play\nservices.\n\nInstall the provider by calling [installProvider(Context)](/android/reference/com/google/android/gms/net/CronetProviderInstaller#installProvider(android.content.Context)), which returns a [Task](/android/reference/com/google/android/gms/tasks/Task). If the\n`Task` completes successfully the provider is installed; otherwise, the\n`Task` will contain one of the following errors:\n\n- 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](//developer.android.com/reference/android/content/Intent.html) to trigger the user interaction.\n- 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. \n\nConstant Summary\n\n|-------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|---------------------------|\n| [String](//developer.android.com/reference/java/lang/String.html) | [PROVIDER_NAME](/android/reference/com/google/android/gms/net/CronetProviderInstaller#PROVIDER_NAME) | The name of the provider. |\n\nPublic Method Summary\n\n|------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e | [installProvider](/android/reference/com/google/android/gms/net/CronetProviderInstaller#installProvider(android.content.Context))([Context](//developer.android.com/reference/android/content/Context.html) context) Installs Cronet provider if it is not already installed. |\n| static boolean | [isInstalled](/android/reference/com/google/android/gms/net/CronetProviderInstaller#isInstalled())() Checks whether the Cronet provider is already installed. |\n\nInherited Method Summary \nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nConstants \n\npublic static final [String](//developer.android.com/reference/java/lang/String.html)\n**PROVIDER_NAME** \nThe name of the provider. \nConstant Value: \"Google-Play-Services-Cronet-Provider\"\n\nPublic Methods \n\npublic static Task\\\u003c[Void](//developer.android.com/reference/java/lang/Void.html)\\\u003e **installProvider** ([Context](//developer.android.com/reference/android/content/Context.html) context) \nInstalls Cronet provider if it is not already installed.\n\nThis method returns a [Task](/android/reference/com/google/android/gms/tasks/Task) object with\nno data associated with it. If the task completes successfully, the Cronet provider has\nbeen successfully installed and will be used when\n`org.chromium.net.CronetEngine.Builder(Context)` constructor is called. In\ncase of an error, the `Task` will contain the corresponding exception, which\ncan be:\n\n- [GooglePlayServicesNotAvailableException](/android/reference/com/google/android/gms/common/GooglePlayServicesNotAvailableException) - if there is no action that the app can take to repair Google Play services.\n- [GooglePlayServicesRepairableException](/android/reference/com/google/android/gms/common/GooglePlayServicesRepairableException) - if an update to Google Play services is required or there is some other issue that can be fixed with user interaction. Refer to `GooglePlayServicesRepairableException` for more details.\n\nIf the provider is already installed, this method immediately returns a successfully\ncompleted `Task` with a guarantee that the first call to [isSuccessful()](/android/reference/com/google/android/gms/tasks/Task#isSuccessful())\nwill return `true`.\n\nUse this method to install the provider asynchronously or synchronously. For the\nasynchronous behavior, the caller can add the corresponding `Task` listeners\nto be notified asynchronously when the result is available. For the synchronous\nbehavior, the caller can call [Tasks.await(...)](/android/reference/com/google/android/gms/tasks/Tasks#await(com.google.android.gms.tasks.Task\u003cTResult\u003e)) to block and wait until the result is available. Note that\n`Tasks.await(...)` must not be called on the main thread. \n\npublic static boolean **isInstalled** () \nChecks whether the Cronet provider is already installed. \n\nReturns\n\n- `true` if the provider is already installed."]]