NetworkRequest.Builder
public
static
class
NetworkRequest.Builder
extends Object
| java.lang.Object | |
| ↳ | android.net.NetworkRequest.Builder |
Builder used to create NetworkRequest objects. Specify the Network features
needed in terms of NetworkCapabilities features
Summary
Public constructors | |
|---|---|
Builder()
Default constructor for Builder. |
|
Public methods | |
|---|---|
NetworkRequest.Builder
|
addCapability(int capability)
Add the given capability requirement to this builder. |
NetworkRequest.Builder
|
addTransportType(int transportType)
Adds the given transport requirement to this builder. |
NetworkRequest
|
build()
Build |
NetworkRequest.Builder
|
clearCapabilities()
Completely clears all the |
NetworkRequest.Builder
|
removeCapability(int capability)
Removes (if found) the given capability from this builder instance. |
NetworkRequest.Builder
|
removeTransportType(int transportType)
Removes (if found) the given transport from this builder instance. |
NetworkRequest.Builder
|
setNetworkSpecifier(NetworkSpecifier networkSpecifier)
Sets the optional bearer specific network specifier. |
NetworkRequest.Builder
|
setNetworkSpecifier(String networkSpecifier)
This method was deprecated
in API level 30.
Use |
Inherited methods | |
|---|---|
Public constructors
Public methods
addCapability
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.
| Returns | |
|---|---|
NetworkRequest.Builder |
The builder to facilitate chaining
builder.addCapability(...).addCapability();. |
addTransportType
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.
| Parameters | |
|---|---|
transportType |
int: The transport type to add.
Value is NetworkCapabilities.TRANSPORT_CELLULAR, NetworkCapabilities.TRANSPORT_WIFI, NetworkCapabilities.TRANSPORT_BLUETOOTH, NetworkCapabilities.TRANSPORT_ETHERNET, NetworkCapabilities.TRANSPORT_VPN, NetworkCapabilities.TRANSPORT_WIFI_AWARE, NetworkCapabilities.TRANSPORT_LOWPAN, or android.net.NetworkCapabilities.TRANSPORT_TEST |
| Returns | |
|---|---|
NetworkRequest.Builder |
The builder to facilitate chaining. |
build
public NetworkRequest build ()
Build NetworkRequest give the current set of capabilities.
| Returns | |
|---|---|
NetworkRequest |
|
clearCapabilities
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.
| Returns | |
|---|---|
NetworkRequest.Builder |
The builder to facilitate chaining.
This value cannot be null. |
removeCapability
public NetworkRequest.Builder removeCapability (int capability)
Removes (if found) the given capability from this builder instance.
| Returns | |
|---|---|
NetworkRequest.Builder |
The builder to facilitate chaining. |
removeTransportType
public NetworkRequest.Builder removeTransportType (int transportType)
Removes (if found) the given transport from this builder instance.
| Parameters | |
|---|---|
transportType |
int: The transport type to remove.
Value is NetworkCapabilities.TRANSPORT_CELLULAR, NetworkCapabilities.TRANSPORT_WIFI, NetworkCapabilities.TRANSPORT_BLUETOOTH, NetworkCapabilities.TRANSPORT_ETHERNET, NetworkCapabilities.TRANSPORT_VPN, NetworkCapabilities.TRANSPORT_WIFI_AWARE, NetworkCapabilities.TRANSPORT_LOWPAN, or android.net.NetworkCapabilities.TRANSPORT_TEST |
| Returns | |
|---|---|
NetworkRequest.Builder |
The builder to facilitate chaining. |
setNetworkSpecifier
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.
| Parameters | |
|---|---|
networkSpecifier |
NetworkSpecifier: A concrete, parcelable framework class that extends
NetworkSpecifier. |
| Returns | |
|---|---|
NetworkRequest.Builder |
|
setNetworkSpecifier
public NetworkRequest.Builder setNetworkSpecifier (String networkSpecifier)
This method was deprecated
in API level 30.
Use 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 thenetworkSpecifier is provided, it shall be interpreted as follows:
- If the specifier can be parsed as an integer, it will be treated as a
TelephonyNetworkSpecifier, 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.
| Parameters | |
|---|---|
networkSpecifier |
String: A String of either a SubscriptionId in cellular
network request or an ethernet interface name in ethernet
network request. |
| Returns | |
|---|---|
NetworkRequest.Builder |
|