Builder

open class Builder
kotlin.Any
   ↳ android.net.NetworkRequest.Builder

Builder used to create NetworkRequest objects. Specify the Network features needed in terms of NetworkCapabilities features

Summary

Public constructors

Default constructor for Builder.

Creates a new Builder of NetworkRequest from an existing instance.

Public methods
open NetworkRequest.Builder!
addCapability(capability: Int)

Add the given capability requirement to this builder.

open NetworkRequest.Builder!
addTransportType(transportType: Int)

Adds the given transport requirement to this builder.

open NetworkRequest!

Build NetworkRequest give the current set of capabilities.

open NetworkRequest.Builder

Completely clears all the NetworkCapabilities from this builder instance, removing even the capabilities that are set by default when the object is constructed.

open NetworkRequest.Builder!
removeCapability(capability: Int)

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

open NetworkRequest.Builder!
removeTransportType(transportType: Int)

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

open NetworkRequest.Builder

Specifies whether the built request should also match networks that do not apply to the calling UID.

open NetworkRequest.Builder!
setNetworkSpecifier(networkSpecifier: String!)

Sets the optional bearer specific network specifier.

open NetworkRequest.Builder!

Sets the optional bearer specific network specifier.

Public constructors

Builder

Builder()

Default constructor for Builder.

Builder

Builder(request: NetworkRequest)

Creates a new Builder of NetworkRequest from an existing instance.

Parameters
request NetworkRequest: This value cannot be null.

Public methods

addCapability

open fun addCapability(capability: Int): NetworkRequest.Builder!

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 android.net.NetworkCapabilities#NET_CAPABILITY_MMS, android.net.NetworkCapabilities#NET_CAPABILITY_SUPL, android.net.NetworkCapabilities#NET_CAPABILITY_DUN, android.net.NetworkCapabilities#NET_CAPABILITY_FOTA, android.net.NetworkCapabilities#NET_CAPABILITY_IMS, android.net.NetworkCapabilities#NET_CAPABILITY_CBS, android.net.NetworkCapabilities#NET_CAPABILITY_WIFI_P2P, android.net.NetworkCapabilities#NET_CAPABILITY_IA, android.net.NetworkCapabilities#NET_CAPABILITY_RCS, android.net.NetworkCapabilities#NET_CAPABILITY_XCAP, android.net.NetworkCapabilities#NET_CAPABILITY_EIMS, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_METERED, android.net.NetworkCapabilities#NET_CAPABILITY_INTERNET, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED, android.net.NetworkCapabilities#NET_CAPABILITY_TRUSTED, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_VPN, android.net.NetworkCapabilities#NET_CAPABILITY_VALIDATED, android.net.NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING, android.net.NetworkCapabilities#NET_CAPABILITY_FOREGROUND, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_CONGESTED, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_SUSPENDED, android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PAID, android.net.NetworkCapabilities#NET_CAPABILITY_MCX, android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY, android.net.NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED, android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, android.net.NetworkCapabilities.NET_CAPABILITY_VEHICLE_INTERNAL, android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED, android.net.NetworkCapabilities#NET_CAPABILITY_ENTERPRISE, android.net.NetworkCapabilities.NET_CAPABILITY_VSIM, android.net.NetworkCapabilities.NET_CAPABILITY_BIP, android.net.NetworkCapabilities#NET_CAPABILITY_HEAD_UNIT, android.net.NetworkCapabilities#NET_CAPABILITY_MMTEL, android.net.NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_LATENCY, android.net.NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_BANDWIDTH, or android.net.NetworkCapabilities.NET_CAPABILITY_LOCAL_NETWORK
Return
NetworkRequest.Builder! The builder to facilitate chaining builder.addCapability(...).addCapability();.

addTransportType

open fun addTransportType(transportType: Int): NetworkRequest.Builder!

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 android.net.NetworkCapabilities#TRANSPORT_CELLULAR, android.net.NetworkCapabilities#TRANSPORT_WIFI, android.net.NetworkCapabilities#TRANSPORT_BLUETOOTH, android.net.NetworkCapabilities#TRANSPORT_ETHERNET, android.net.NetworkCapabilities#TRANSPORT_VPN, android.net.NetworkCapabilities#TRANSPORT_WIFI_AWARE, android.net.NetworkCapabilities#TRANSPORT_LOWPAN, android.net.NetworkCapabilities.TRANSPORT_TEST, android.net.NetworkCapabilities#TRANSPORT_USB, or android.net.NetworkCapabilities#TRANSPORT_THREAD
Return
NetworkRequest.Builder! The builder to facilitate chaining.

build

open fun build(): NetworkRequest!

Build NetworkRequest give the current set of capabilities.

clearCapabilities

open fun clearCapabilities(): NetworkRequest.Builder

Completely clears all the NetworkCapabilities from this builder instance, removing even the capabilities that are set by default when the object is constructed. Also removes any set forbidden capabilities.

Return
NetworkRequest.Builder The builder to facilitate chaining. This value cannot be null.

removeCapability

open fun removeCapability(capability: Int): NetworkRequest.Builder!

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

Parameters
capability Int: The capability to remove. Value is android.net.NetworkCapabilities#NET_CAPABILITY_MMS, android.net.NetworkCapabilities#NET_CAPABILITY_SUPL, android.net.NetworkCapabilities#NET_CAPABILITY_DUN, android.net.NetworkCapabilities#NET_CAPABILITY_FOTA, android.net.NetworkCapabilities#NET_CAPABILITY_IMS, android.net.NetworkCapabilities#NET_CAPABILITY_CBS, android.net.NetworkCapabilities#NET_CAPABILITY_WIFI_P2P, android.net.NetworkCapabilities#NET_CAPABILITY_IA, android.net.NetworkCapabilities#NET_CAPABILITY_RCS, android.net.NetworkCapabilities#NET_CAPABILITY_XCAP, android.net.NetworkCapabilities#NET_CAPABILITY_EIMS, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_METERED, android.net.NetworkCapabilities#NET_CAPABILITY_INTERNET, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED, android.net.NetworkCapabilities#NET_CAPABILITY_TRUSTED, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_VPN, android.net.NetworkCapabilities#NET_CAPABILITY_VALIDATED, android.net.NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING, android.net.NetworkCapabilities#NET_CAPABILITY_FOREGROUND, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_CONGESTED, android.net.NetworkCapabilities#NET_CAPABILITY_NOT_SUSPENDED, android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PAID, android.net.NetworkCapabilities#NET_CAPABILITY_MCX, android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY, android.net.NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED, android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, android.net.NetworkCapabilities.NET_CAPABILITY_VEHICLE_INTERNAL, android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED, android.net.NetworkCapabilities#NET_CAPABILITY_ENTERPRISE, android.net.NetworkCapabilities.NET_CAPABILITY_VSIM, android.net.NetworkCapabilities.NET_CAPABILITY_BIP, android.net.NetworkCapabilities#NET_CAPABILITY_HEAD_UNIT, android.net.NetworkCapabilities#NET_CAPABILITY_MMTEL, android.net.NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_LATENCY, android.net.NetworkCapabilities#NET_CAPABILITY_PRIORITIZE_BANDWIDTH, or android.net.NetworkCapabilities.NET_CAPABILITY_LOCAL_NETWORK
Return
NetworkRequest.Builder! The builder to facilitate chaining.

setIncludeOtherUidNetworks

open fun setIncludeOtherUidNetworks(include: Boolean): NetworkRequest.Builder

Specifies whether the built request should also match networks that do not apply to the calling UID. By default, the built request will only match networks that apply to the calling UID. If this method is called with true, the built request will match any network on the system that matches the other parameters of the request. In this case, any information in the built request that is subject to redaction for security or privacy purposes, such as a NetworkSpecifier, will be redacted or removed to prevent the application deducing sensitive information.

Parameters
include Boolean: Whether to match networks that do not apply to the calling UID.
Return
NetworkRequest.Builder The builder to facilitate chaining. This value cannot be null.

setNetworkSpecifier

Added in API level 21
Also in U Extensions 1
Deprecated in API level 30
open fun setNetworkSpecifier(networkSpecifier: String!): NetworkRequest.Builder!

Deprecated: Use setNetworkSpecifier(android.net.NetworkSpecifier) instead.

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.

If the networkSpecifier is provided, it shall be interpreted as follows:
  • If the specifier can be parsed as an integer, it will be treated as a TelephonyNetworkSpecifier, and the provided integer will be interpreted as a SubscriptionId.
  • If the value is an ethernet interface name, it will be treated as such.
  • For all other cases, the behavior is undefined.
Parameters
networkSpecifier String!: A String of either a SubscriptionId in cellular network request or an ethernet interface name in ethernet network request.

setNetworkSpecifier

open fun setNetworkSpecifier(networkSpecifier: NetworkSpecifier!): NetworkRequest.Builder!

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.