Most visited

Recently visited

Added in API level 21

NetworkRequest.Builder

public static class NetworkRequest.Builder
extends Object

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


Builder用于创建NetworkRequest对象。 根据NetworkCapabilities功能指定所需的网络功能

Summary

Public constructors

NetworkRequest.Builder()

Builder的默认构造函数。

Public methods

NetworkRequest.Builder addCapability(int capability)

将给定的功能要求添加到此构建器。

NetworkRequest.Builder addTransportType(int transportType)

将给定的运输要求添加到此构建器。

NetworkRequest build()

Build NetworkRequest给出了当前的一组功能。

NetworkRequest.Builder removeCapability(int capability)

从该构建器实例中移除(如果找到)给定的功能。

NetworkRequest.Builder removeTransportType(int transportType)

从该构建器实例中移除(如果找到)给定的传输。

NetworkRequest.Builder setNetworkSpecifier(String networkSpecifier)

设置可选的承载特定网络说明符。

Inherited methods

From class java.lang.Object

Public constructors

NetworkRequest.Builder

Added in API level 21
NetworkRequest.Builder ()

Builder的默认构造函数。

Public methods

addCapability

Added in API level 21
NetworkRequest.Builder addCapability (int capability)

将给定的功能要求添加到此构建器。 这些代表了请求的网络所需的功能。 请注意,在搜索网络以满足请求时,必须满足所请求的所有功能。 NetworkCapabilitiesNET_CAPABILITIY_*的定义。

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)

将给定的运输要求添加到此构建器。 这些代表请求允许的传输集合。 只有使用其中一种传输方式的网络才能满足请求。 如果不需要特殊的传输,则不需要在这里指定。 NetworkCapabilitiesTRANSPORT_*的定义。

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提供当前的一组功能。

Returns
NetworkRequest

removeCapability

Added in API level 21
NetworkRequest.Builder removeCapability (int capability)

从该构建器实例中移除(如果找到)给定的功能。

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)

从该构建器实例中移除(如果找到)给定的传输。

Parameters
transportType int: The NetworkCapabilities.TRANSPORT_* to remove.
Returns
NetworkRequest.Builder The builder to facilitate chaining.

setNetworkSpecifier

Added in API level 21
NetworkRequest.Builder setNetworkSpecifier (String networkSpecifier)

设置可选的承载特定网络说明符。 如果没有指定单个传输,那么这没有意义,因此在没有单个传输集的情况下调用此传输将会生成一个异常,随后在设置传输后添加或删除传输。

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

Hooray!