Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/net/NetworkRequest.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/net/NetworkRequest.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/NetworkRequest.Builder#inhmethods)

# NetworkRequest.Builder

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder "View this page in Kotlin") \|Java


`
public
static


class
NetworkRequest.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.NetworkRequest.Builder |

<br />

*** ** * ** ***

Builder used to create `https://developer.android.com/reference/android/net/NetworkRequest` objects. Specify the Network features
needed in terms of `https://developer.android.com/reference/android/net/NetworkCapabilities` features

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#Builder()() ` Default constructor for Builder. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#Builder(android.net.NetworkRequest)(https://developer.android.com/reference/android/net/NetworkRequest request) ` Creates a new Builder of NetworkRequest from an existing instance. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#addCapability(int)(int capability) ` Add the given capability requirement to this builder. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#addTransportType(int)(int transportType) ` Adds the given transport requirement to this builder. |
| ` https://developer.android.com/reference/android/net/NetworkRequest` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#build()() ` Build `https://developer.android.com/reference/android/net/NetworkRequest` give the current set of capabilities. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#clearCapabilities()() ` Completely clears all the `NetworkCapabilities` from this builder instance, removing even the capabilities that are set by default when the object is constructed. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#removeCapability(int)(int capability) ` Removes (if found) the given capability from this builder instance. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#removeTransportType(int)(int transportType) ` Removes (if found) the given transport from this builder instance. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#setIncludeOtherUidNetworks(boolean)(boolean include) ` Specifies whether the built request should also match networks that do not apply to the calling UID. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(android.net.NetworkSpecifier)(https://developer.android.com/reference/android/net/NetworkSpecifier networkSpecifier) ` Sets the optional bearer specific network specifier. |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(java.lang.String)(https://developer.android.com/reference/java/lang/String networkSpecifier) ` *This method was deprecated in API level 30. Use `https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(android.net.NetworkSpecifier)` instead.* |
| ` https://developer.android.com/reference/android/net/NetworkRequest.Builder` | ` https://developer.android.com/reference/android/net/NetworkRequest.Builder#setSubscriptionIds(java.util.Set<java.lang.Integer>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/Integer> subIds) ` Sets the optional subscription ID set. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### Builder

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

```
public Builder ()
```

Default constructor for Builder.

<br />

### Builder

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

```
public Builder (NetworkRequest request)
```

Creates a new Builder of NetworkRequest from an existing instance.

<br />

| Parameters ||
|---|---|
| `request` | `NetworkRequest`: This value cannot be `null`. <br /> |

## Public methods

### addCapability

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

```
public NetworkRequest.Builder addCapability (int capability)
```

Add the given capability requirement to this builder. These represent
the requested network's required capabilities. Note that when searching
for a network to satisfy a request, all capabilities requested must be
satisfied.

<br />

| Parameters ||
|---|---|
| `capability` | `int`: The capability to add. Value is one of the following: - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_SUPL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_DUN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_FOTA` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_IMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_CBS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_WIFI_P2P` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_IA` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_RCS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_XCAP` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_EIMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_METERED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_INTERNET` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_TRUSTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_VPN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_VALIDATED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_FOREGROUND` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_CONGESTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_SUSPENDED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MCX` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_ENTERPRISE` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_HEAD_UNIT` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MMTEL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_LATENCY` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_BANDWIDTH` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_LOCAL_NETWORK` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_UNIFIED_COMMUNICATIONS` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining `builder.addCapability(...).addCapability();`. <br /> |

### addTransportType

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

```
public NetworkRequest.Builder addTransportType (int transportType)
```

Adds the given transport requirement to this builder. These represent
the set of allowed transports for the request. Only networks using one
of these transports will satisfy the request. If no particular transports
are required, none should be specified here.

<br />

| Parameters ||
|---|---|
| `transportType` | `int`: The transport type to add. Value is one of the following: - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_CELLULAR` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_WIFI` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_BLUETOOTH` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_ETHERNET` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_VPN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_WIFI_AWARE` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_LOWPAN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_USB` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_THREAD` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_SATELLITE` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining. <br /> |

### build

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

```
public NetworkRequest build ()
```

Build `https://developer.android.com/reference/android/net/NetworkRequest` give the current set of capabilities.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest` | <br /> |

### clearCapabilities

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

```
public NetworkRequest.Builder clearCapabilities ()
```

Completely clears all the `NetworkCapabilities` from this builder instance,
removing even the capabilities that are set by default when the object is constructed.
Also removes any set forbidden capabilities.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining. This value cannot be `null`. <br /> |

### removeCapability

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

```
public NetworkRequest.Builder removeCapability (int capability)
```

Removes (if found) the given capability from this builder instance.

<br />

| Parameters ||
|---|---|
| `capability` | `int`: The capability to remove. Value is one of the following: - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_SUPL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_DUN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_FOTA` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_IMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_CBS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_WIFI_P2P` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_IA` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_RCS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_XCAP` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_EIMS` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_METERED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_INTERNET` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_TRUSTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_VPN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_VALIDATED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_FOREGROUND` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_CONGESTED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_SUSPENDED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MCX` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_ENTERPRISE` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_HEAD_UNIT` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_MMTEL` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_LATENCY` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_BANDWIDTH` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_LOCAL_NETWORK` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED` - `https://developer.android.com/reference/android/net/NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_UNIFIED_COMMUNICATIONS` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining. <br /> |

### removeTransportType

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

```
public NetworkRequest.Builder removeTransportType (int transportType)
```

Removes (if found) the given transport from this builder instance.

<br />

| Parameters ||
|---|---|
| `transportType` | `int`: The transport type to remove. Value is one of the following: - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_CELLULAR` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_WIFI` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_BLUETOOTH` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_ETHERNET` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_VPN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_WIFI_AWARE` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_LOWPAN` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_USB` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_THREAD` - `https://developer.android.com/reference/android/net/NetworkCapabilities#TRANSPORT_SATELLITE` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining. <br /> |

### setIncludeOtherUidNetworks

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

```
public NetworkRequest.Builder setIncludeOtherUidNetworks (boolean include)
```

Specifies whether the built request should also match networks that do not apply to the
calling UID.

By default, the built request will only match networks that apply to the calling UID.
If this method is called with `true`, the built request will match any network on
the system that matches the other parameters of the request. In this case, any
information in the built request that is subject to redaction for security or privacy
purposes, such as a `https://developer.android.com/reference/android/net/NetworkSpecifier`, will be redacted or removed to prevent the
application deducing sensitive information.

<br />

| Parameters ||
|---|---|
| `include` | `boolean`: Whether to match networks that do not apply to the calling UID. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | The builder to facilitate chaining. This value cannot be `null`. <br /> |

### setNetworkSpecifier

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

```
public NetworkRequest.Builder setNetworkSpecifier (NetworkSpecifier networkSpecifier)
```

Sets the optional bearer specific network specifier.
This has no meaning if a single transport is also not specified, so calling
this without a single transport set will generate an exception, as will
subsequently adding or removing transports after this is set.

<br />

<br />

| Parameters ||
|---|---|
| `networkSpecifier` | `NetworkSpecifier`: A concrete, parcelable framework class that extends NetworkSpecifier. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | <br /> |

### setNetworkSpecifier

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

```
public NetworkRequest.Builder setNetworkSpecifier (String networkSpecifier)
```


**This method was deprecated
in API level 30.**   

Use `https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(android.net.NetworkSpecifier)` instead.

Sets the optional bearer specific network specifier.
This has no meaning if a single transport is also not specified, so calling
this without a single transport set will generate an exception, as will
subsequently adding or removing transports after this is set.
If the `networkSpecifier` is provided, it shall be interpreted as follows:

- If the specifier can be parsed as an integer, it will be treated as a `https://developer.android.com/reference/android/net/package-summary`, and the provided integer will be interpreted as a SubscriptionId.
- If the value is an ethernet interface name, it will be treated as such.
- For all other cases, the behavior is undefined.

<br />

<br />

| Parameters ||
|---|---|
| `networkSpecifier` | `String`: A `String` of either a SubscriptionId in cellular network request or an ethernet interface name in ethernet network request. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | <br /> |

### setSubscriptionIds

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [U Extensions 12](https://developer.android.com/sdkExtensions)

```
public NetworkRequest.Builder setSubscriptionIds (Set<Integer> subIds)
```

Sets the optional subscription ID set.


This specify the subscription IDs requirement.
A network will satisfy this request only if it matches one of the subIds in this set.
An empty set matches all networks, including those without a subId.

Registering a NetworkRequest with a non-empty set of subIds requires the
NETWORK_FACTORY permission.

<br />

| Parameters ||
|---|---|
| `subIds` | `Set`: A `Set` that represents subscription IDs. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkRequest.Builder` | This value cannot be `null`. <br /> |