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

Public Constructors

public NetworkRequest.Builder ()

Default constructor for Builder.

Public Methods

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. 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)

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

Build NetworkRequest give the current set of capabilities.

public NetworkRequest.Builder removeCapability (int capability)

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)

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

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