Most visited

Recently visited

Added in API level 21

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

NetworkRequest.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 give the current set of capabilities.

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(String networkSpecifier)

Sets the optional bearer specific network specifier.

Inherited methods

From class java.lang.Object

Public constructors

NetworkRequest.Builder

Added in API level 21
NetworkRequest.Builder ()

Default constructor for Builder.

Public methods

addCapability

Added in API level 21
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. See NetworkCapabilities for NET_CAPABILITIY_* definitions.

Parameters
capability int: The NetworkCapabilities.NET_CAPABILITY_* to add.
Returns
NetworkRequest.Builder The builder to facilitate chaining builder.addCapability(...).addCapability();.

addTransportType

Added in API level 21
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. See NetworkCapabilities for TRANSPORT_* definitions.

Parameters
transportType int: The NetworkCapabilities.TRANSPORT_* to add.
Returns
NetworkRequest.Builder The builder to facilitate chaining.

build

Added in API level 21
NetworkRequest build ()

Build NetworkRequest give the current set of capabilities.

Returns
NetworkRequest

removeCapability

Added in API level 21
NetworkRequest.Builder removeCapability (int capability)

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

Parameters
capability int: The NetworkCapabilities.NET_CAPABILITY_* to remove.
Returns
NetworkRequest.Builder The builder to facilitate chaining.

removeTransportType

Added in API level 21
NetworkRequest.Builder removeTransportType (int transportType)

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

Parameters
transportType int: The NetworkCapabilities.TRANSPORT_* to remove.
Returns
NetworkRequest.Builder The builder to facilitate chaining.

setNetworkSpecifier

Added in API level 21
NetworkRequest.Builder setNetworkSpecifier (String 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.

The interpretation of this String is bearer specific and bearers that use it should document their particulars. For example, Bluetooth may use some sort of device id while WiFi could used ssid and/or bssid. Cellular may use carrier spn.

Parameters
networkSpecifier String: An String of opaque format used to specify the bearer specific network specifier where the bearer has a choice of networks.
Returns
NetworkRequest.Builder

Hooray!