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 | |
---|---|
Builder() Default constructor for Builder. |
|
Builder(request: NetworkRequest) 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() Build |
open NetworkRequest.Builder |
Completely clears all the |
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 |
setIncludeOtherUidNetworks(include: Boolean) 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! |
setNetworkSpecifier(networkSpecifier: NetworkSpecifier!) Sets the optional bearer specific network specifier. |
open NetworkRequest.Builder |
setSubscriptionIds(subIds: MutableSet<Int!>) Sets the optional subscription ID set. |
Public constructors
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.
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 , android.net.NetworkCapabilities#TRANSPORT_THREAD , or android.net.NetworkCapabilities#TRANSPORT_SATELLITE |
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.
Return | |
---|---|
NetworkRequest.Builder! |
The builder to facilitate chaining. |
removeTransportType
open fun removeTransportType(transportType: Int): NetworkRequest.Builder!
Removes (if found) the given transport from this builder instance.
Parameters | |
---|---|
transportType |
Int: The transport type to remove. 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 , android.net.NetworkCapabilities#TRANSPORT_THREAD , or android.net.NetworkCapabilities#TRANSPORT_SATELLITE |
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
open funsetNetworkSpecifier(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 thenetworkSpecifier
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. |
setSubscriptionIds
open fun setSubscriptionIds(subIds: MutableSet<Int!>): NetworkRequest.Builder
Sets the optional subscription ID set.
This specify the subscription IDs requirement. A network will satisfy this request only if it matches one of the subIds in this set. An empty set matches all networks, including those without a subId.
Registering a NetworkRequest with a non-empty set of subIds requires the NETWORK_FACTORY permission.
Parameters | |
---|---|
subIds |
MutableSet<Int!>: A Set that represents subscription IDs. This value cannot be null . |
Return | |
---|---|
NetworkRequest.Builder |
This value cannot be null . |