Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.app.admin.PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) |

Builder used to create `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig` objects. Specify the preferred Network preference

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#Builder()()` Constructs an empty Builder with preferential network disabled by default. |

| Public methods ||
|---|---|
| [PreferentialNetworkServiceConfig](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#build()()` Returns an instance of `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig` created from the fields set on this builder. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setEnabled(kotlin.Boolean)(isEnabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Set the preferential network service enabled state. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setExcludedUids(kotlin.IntArray)(uids: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int-array/index.html)` Set the array of uids who are not allowed through this preferential network service. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setFallbackToDefaultConnectionAllowed(kotlin.Boolean)(allowFallbackToDefaultConnection: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Set whether fallback to the device-wide default network is allowed. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setIncludedUids(kotlin.IntArray)(uids: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int-array/index.html)` Set the array of uids whose network access will go through this preferential network service. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setNetworkId(kotlin.Int)(preferenceId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the preferential network identifier. |
| [PreferentialNetworkServiceConfig.Builder](https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#) | `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setShouldBlockNonMatchingNetworks(kotlin.Boolean)(blockNonMatchingNetworks: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Set whether to block UIDs from using other networks than the preferential service. |

## Public constructors

### Builder

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder()
```

Constructs an empty Builder with preferential network disabled by default.

## Public methods

### build

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): PreferentialNetworkServiceConfig
```

Returns an instance of `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig` created from the fields set on this builder.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig` | This value cannot be `null`. |

### setEnabled

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setEnabled(isEnabled: Boolean): PreferentialNetworkServiceConfig.Builder
```

Set the preferential network service enabled state. Default value is false.

| Parameters ||
|---|---|
| `isEnabled` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): the desired network preference to use, true to enable else false |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |

### setExcludedUids

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setExcludedUids(uids: IntArray): PreferentialNetworkServiceConfig.Builder
```

Set the array of uids who are not allowed through this preferential network service. Included UIDs and Excluded UIDs can't both be non-empty. if both are empty, it means this request applies to all uids in the user profile. if included is not empty, then only included UIDs are applied. if excluded is not empty, then it is all uids in the user profile except these UIDs.

| Parameters ||
|---|---|
| `uids` | [IntArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int-array/index.html): array of excluded uids. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setIncludedUids(kotlin.IntArray)`

### setFallbackToDefaultConnectionAllowed

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setFallbackToDefaultConnectionAllowed(allowFallbackToDefaultConnection: Boolean): PreferentialNetworkServiceConfig.Builder
```

Set whether fallback to the device-wide default network is allowed.

This boolean configures whether the default connection (e.g. general cell network or wifi) should be used if no preferential network service connection is available. If true, the default connection will be used when no preferential service is available. If false, the UIDs subject to this configuration will have no default network. Note that while this boolean determines whether the UIDs subject to this configuration have a default network in the absence of a preferential service, apps can still explicitly decide to use another network than their default network by requesting them from the system. This boolean does not determine whether the UIDs are blocked from using such other networks. Use `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setShouldBlockNonMatchingNetworks(kotlin.Boolean)` to specify this.

The default value is true.

| Parameters ||
|---|---|
| `allowFallbackToDefaultConnection` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): true if fallback is allowed else false |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |

### setIncludedUids

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setIncludedUids(uids: IntArray): PreferentialNetworkServiceConfig.Builder
```

Set the array of uids whose network access will go through this preferential network service. Included UIDs and Excluded UIDs can't both be non-empty. if both are empty, it means this request applies to all uids in the user profile. if included is not empty, then only included UIDs are applied. if excluded is not empty, then it is all uids in the user profile except these UIDs.

| Parameters ||
|---|---|
| `uids` | [IntArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int-array/index.html): array of included uids. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setExcludedUids(kotlin.IntArray)`

### setNetworkId

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setNetworkId(preferenceId: Int): PreferentialNetworkServiceConfig.Builder
```

Set the preferential network identifier. preference identifier is applicable only if preferential network service is enabled.

| Parameters ||
|---|---|
| `preferenceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): preference Id. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig#PREFERENTIAL_NETWORK_ID_1:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig#PREFERENTIAL_NETWORK_ID_2:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig#PREFERENTIAL_NETWORK_ID_3:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig#PREFERENTIAL_NETWORK_ID_4:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig#PREFERENTIAL_NETWORK_ID_5:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |

### setShouldBlockNonMatchingNetworks

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setShouldBlockNonMatchingNetworks(blockNonMatchingNetworks: Boolean): PreferentialNetworkServiceConfig.Builder
```

Set whether to block UIDs from using other networks than the preferential service.

Apps can inspect the list of available networks on the device and choose to use multiple of them concurrently for performance, privacy or other reasons. This boolean configures whether the concerned UIDs should be blocked from using networks that do not match the configured preferential network service even if these networks are otherwise open to all apps.

The default value is false. This value can only be set to `true` if `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#setFallbackToDefaultConnectionAllowed(kotlin.Boolean)` is set to `false`, because allowing fallback but blocking it does not make sense. Failure to comply with this constraint will throw when building the object.

| Parameters ||
|---|---|
| `blockNonMatchingNetworks` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): true if UIDs should be blocked from using non-matching networks. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/admin/PreferentialNetworkServiceConfig.Builder#` | The builder to facilitate chaining. This value cannot be `null`. |