# CronetUtil

Artifact: [androidx.media3:media3-datasource-cronet](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/cronet/CronetUtil.java+class:androidx.media3.datasource.cronet.CronetUtil)

*** ** * ** ***


```
public final class CronetUtil
```

<br />

*** ** * ** ***

Cronet utility methods.

## Summary

| ### Public methods |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` | `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetUtil#buildCronetEngine(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` Builds a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` suitable for use with `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource`. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetUtil#buildCronetEngine(android.content.Context,java.lang.String,boolean)( https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html userAgent, boolean preferGooglePlayServices )` Builds a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` suitable for use with `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource`. |

## Public methods

### buildCronetEngine

```
public static @Nullable CronetEngine buildCronetEngine(Context context)
```

Builds a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` suitable for use with `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource`. When choosing a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetProvider.html` to build the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, disabled providers are not considered. Neither are fallback providers, since it's more efficient to use `https://developer.android.com/reference/androidx/media3/datasource/DefaultHttpDataSource` than it is to use `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource` with a fallback `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`.

Note that it's recommended for applications to create only one instance of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, 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](https://developer.android.com/guide/topics/connectivity/cronet/start) to learn more about using Cronet for network operations.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` | The `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, 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 `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` suitable for use with `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource`. When choosing a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetProvider.html` to build the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, disabled providers are not considered. Neither are fallback providers, since it's more efficient to use `https://developer.android.com/reference/androidx/media3/datasource/DefaultHttpDataSource` than it is to use `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource` with a fallback `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`.

Note that it's recommended for applications to create only one instance of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, 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](https://developer.android.com/guide/topics/connectivity/cronet/start) to learn more about using Cronet for network operations.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html userAgent` | A default user agent, or `null` to use a default user agent of the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`. |
| `boolean preferGooglePlayServices` | Whether Cronet from Google Play Services should be preferred over Cronet Embedded, if both are available. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html` | The `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.html`, or `null` if no suitable engine could be built. |