Android APIs
public static class

NetworkRequest.Builder

extends Object
java.lang.Object
   ↳ android.net.NetworkRequest.Builder

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public NetworkRequest.Builder ()

Added in API level 21

Default constructor for Builder.

Public Methods

public NetworkRequest.Builder addCapability (int capability)

Added in API level 21

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 The NetworkCapabilities.NET_CAPABILITY_* to add.
Returns
  • The builder to facilitate chaining builder.addCapability(...).addCapability();.

public NetworkRequest.Builder addTransportType (int transportType)

Added in API level 21

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 The NetworkCapabilities.TRANSPORT_* to add.
Returns
  • The builder to facilitate chaining.

public NetworkRequest build ()

Added in API level 21

Build NetworkRequest give the current set of capabilities.

public NetworkRequest.Builder removeCapability (int capability)

Added in API level 21

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

Parameters
capability The NetworkCapabilities.NET_CAPABILITY_* to remove.
Returns
  • The builder to facilitate chaining.

public NetworkRequest.Builder removeTransportType (int transportType)

Added in API level 21

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

Parameters
transportType The NetworkCapabilities.TRANSPORT_* to remove.
Returns
  • The builder to facilitate chaining.

public NetworkRequest.Builder setNetworkSpecifier (String networkSpecifier)

Added in API level 21

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 An String of opaque format used to specify the bearer specific network specifier where the bearer has a choice of networks.