lightbulb_outline Please take our October 2018 developer survey. Start survey

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

Sets the optional bearer specific network specifier.

NetworkRequest.Builder setNetworkSpecifier(String networkSpecifier)

Sets the optional bearer specific network specifier.

Inherited methods

Public constructors

NetworkRequest.Builder

added in API level 21
public NetworkRequest.Builder ()

Default constructor for Builder.

Public methods

addCapability

added in API level 21
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.

Parameters
capability int: The capability to add.

Value is NET_CAPABILITY_MMS, NET_CAPABILITY_SUPL, NET_CAPABILITY_DUN, NET_CAPABILITY_FOTA, NET_CAPABILITY_IMS, NET_CAPABILITY_CBS, NET_CAPABILITY_WIFI_P2P, NET_CAPABILITY_IA, NET_CAPABILITY_RCS, NET_CAPABILITY_XCAP, NET_CAPABILITY_EIMS, NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_INTERNET, NET_CAPABILITY_NOT_RESTRICTED, NET_CAPABILITY_TRUSTED, NET_CAPABILITY_NOT_VPN, NET_CAPABILITY_VALIDATED, NET_CAPABILITY_CAPTIVE_PORTAL, NET_CAPABILITY_NOT_ROAMING, NET_CAPABILITY_FOREGROUND, NET_CAPABILITY_NOT_CONGESTED or NET_CAPABILITY_NOT_SUSPENDED.

Returns
NetworkRequest.Builder The builder to facilitate chaining builder.addCapability(...).addCapability();.

addTransportType

added in API level 21
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 TRANSPORT_CELLULAR, TRANSPORT_WIFI, TRANSPORT_BLUETOOTH, TRANSPORT_ETHERNET, TRANSPORT_VPN, TRANSPORT_WIFI_AWARE or TRANSPORT_LOWPAN.

Returns
NetworkRequest.Builder The builder to facilitate chaining.

build

added in API level 21
public NetworkRequest build ()

Build NetworkRequest give the current set of capabilities.

Returns
NetworkRequest

removeCapability

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

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

Parameters
capability int: The capability to remove.

Value is NET_CAPABILITY_MMS, NET_CAPABILITY_SUPL, NET_CAPABILITY_DUN, NET_CAPABILITY_FOTA, NET_CAPABILITY_IMS, NET_CAPABILITY_CBS, NET_CAPABILITY_WIFI_P2P, NET_CAPABILITY_IA, NET_CAPABILITY_RCS, NET_CAPABILITY_XCAP, NET_CAPABILITY_EIMS, NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_INTERNET, NET_CAPABILITY_NOT_RESTRICTED, NET_CAPABILITY_TRUSTED, NET_CAPABILITY_NOT_VPN, NET_CAPABILITY_VALIDATED, NET_CAPABILITY_CAPTIVE_PORTAL, NET_CAPABILITY_NOT_ROAMING, NET_CAPABILITY_FOREGROUND, NET_CAPABILITY_NOT_CONGESTED or NET_CAPABILITY_NOT_SUSPENDED.

Returns
NetworkRequest.Builder The builder to facilitate chaining.

removeTransportType

added in API level 21
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 TRANSPORT_CELLULAR, TRANSPORT_WIFI, TRANSPORT_BLUETOOTH, TRANSPORT_ETHERNET, TRANSPORT_VPN, TRANSPORT_WIFI_AWARE or TRANSPORT_LOWPAN.

Returns
NetworkRequest.Builder The builder to facilitate chaining.

setNetworkSpecifier

added in API level 26
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

added in API level 21
public 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