Skip to content

Most visited

Recently visited

navigation

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

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_CAPABILITY_* 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 26
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
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

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)