Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder "View this page in Java")

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.net.wifi.aware.WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) |

A builder class for a Wi-Fi Aware network specifier to set up an Aware connection with a peer.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.DiscoverySession,%20android.net.wifi.aware.PeerHandle)(discoverySession: https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession, peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle)` Create a builder for `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier` used in requests to set up a Wi-Fi Aware connection with a specific peer. |
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.PublishDiscoverySession)(publishDiscoverySession: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession)` Create a builder for `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier` used in requests to set up a Wi-Fi Aware connection. |

| Public methods ||
|---|---|
| [WifiAwareNetworkSpecifier](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#build()()` Create a `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#setNetworkSpecifier(android.net.NetworkSpecifier)` for a WiFi Aware connection (link) to the specified peer. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setChannelFrequencyMhz(kotlin.Int,%20kotlin.Boolean)(channelInMhz: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, required: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Configure the Channel frequency for the Wi-Fi Aware connection being requested. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)(securityConfig: https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareDataPathSecurityConfig)` Configure security config for the Wi-Fi Aware connection being requested. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(kotlin.ByteArray)(pmk: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)` Configure the PMK for the Wi-Fi Aware connection being requested. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPort(kotlin.Int)(port: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Configure the port number which will be used to create a connection over this link. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(kotlin.String)(pskPassphrase: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Configure the PSK Passphrase for the Wi-Fi Aware connection being requested. |
| [WifiAwareNetworkSpecifier.Builder](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setTransportProtocol(kotlin.Int)(transportProtocol: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Configure the transport protocol which will be used to create a connection over this link. |

## Public constructors

### Builder

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder(
    discoverySession: DiscoverySession, 
    peerHandle: PeerHandle)
```

Create a builder for `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier` used in requests to set up a Wi-Fi Aware connection with a specific peer.

To set up a connection to any peer or to multiple peers use `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.PublishDiscoverySession)`.

| Parameters ||
|---|---|
| `discoverySession` | [DiscoverySession](https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession): A Wi-Fi Aware discovery session in whose context the connection is created. This value cannot be `null`. |
| `peerHandle` | [PeerHandle](https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle): The handle of the peer to which the Wi-Fi Aware connection is requested. The peer is discovered through Wi-Fi Aware discovery. The handle can be obtained through `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.PeerHandle,%20kotlin.ByteArray,%20kotlin.collections.MutableList)` or `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20kotlin.ByteArray)`. This value cannot be `null`. |

### Builder

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder(publishDiscoverySession: PublishDiscoverySession)
```

Create a builder for `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier` used in requests to set up a Wi-Fi Aware connection. This configuration allows connections to any peers or to multiple peers (as opposed to only a specific peer with `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.DiscoverySession,%20android.net.wifi.aware.PeerHandle)`).

Multiple connections can be triggered by this configuration and using a single request via `https://developer.android.com/reference/kotlin/android/net/ConnectivityManager.html#requestNetwork(android.net.NetworkRequest,%20android.net.ConnectivityManager.NetworkCallback)` and similar methods. Each successful connection will be signaled via the standard Connectivity Manager mechanisms - `https://developer.android.com/reference/kotlin/android/net/ConnectivityManager.NetworkCallback.html#onAvailable(android.net.Network)`. Calling `https://developer.android.com/reference/kotlin/android/net/ConnectivityManager.html#unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback)` will terminate all connections.

| Parameters ||
|---|---|
| `publishDiscoverySession` | [PublishDiscoverySession](https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession): This value cannot be `null`. |

## Public methods

### build

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): WifiAwareNetworkSpecifier
```

Create a `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#setNetworkSpecifier(android.net.NetworkSpecifier)` for a WiFi Aware connection (link) to the specified peer. The `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#addTransportType(kotlin.Int)` should be set to `https://developer.android.com/reference/kotlin/android/net/NetworkCapabilities.html#TRANSPORT_WIFI_AWARE:kotlin.Int`.

The default builder constructor will initialize a NetworkSpecifier which requests an open (non-encrypted) link. To request an encrypted link use the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(kotlin.String)` or `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(kotlin.ByteArray)` builder methods.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier` | A `https://developer.android.com/reference/kotlin/android/net/NetworkSpecifier.html#` to be used to construct `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#setNetworkSpecifier(android.net.NetworkSpecifier)` to pass to `https://developer.android.com/reference/kotlin/android/net/ConnectivityManager.html#requestNetwork(android.net.NetworkRequest,%20android.net.ConnectivityManager.NetworkCallback)` \[or other varieties of that API\]. This value cannot be `null`. |

### setChannelFrequencyMhz

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setChannelFrequencyMhz(
    channelInMhz: Int, 
    required: Boolean
): WifiAwareNetworkSpecifier.Builder
```

Configure the Channel frequency for the Wi-Fi Aware connection being requested. This method is optional - if not called, then channelInMhz to use will be decided by firmware. Only use this when `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareManager#isSetChannelOnDataPathSupported()` is true, otherwise the set channelInMhz will be ignored.

| Parameters ||
|---|---|
| `channelInMhz` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Channel frequency in Mhz. Value is 0 or greater |
| `required` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): If set to true, Channel request is specified and must be respected. If the firmware cannot honor the request then the data-path request is rejected. Otherwise, requested channelInMhz is a recommendation and may be overridden by the firmware. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |

### setDataPathSecurityConfig

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setDataPathSecurityConfig(securityConfig: WifiAwareDataPathSecurityConfig): WifiAwareNetworkSpecifier.Builder
```

Configure security config for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: this method is the superset of the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(kotlin.ByteArray)` and `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(kotlin.String)`.

| Parameters ||
|---|---|
| `securityConfig` | [WifiAwareDataPathSecurityConfig](https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareDataPathSecurityConfig): The (optional) security config to be used to encrypt the link. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |

### setPmk

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setPmk(pmk: ByteArray): WifiAwareNetworkSpecifier.Builder
```

Configure the PMK for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: Use `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)` to avoid interoperability issues when devices support different cipher suites by explicitly specifying a cipher suite as opposed to relying on a default cipher suite.

| Parameters ||
|---|---|
| `pmk` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html): A PMK (pairwise master key, see IEEE 802.11i) specifying the key to use for encrypting the data-path. Use the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(kotlin.String)` to specify a Passphrase. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |

### setPort

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setPort(port: Int): WifiAwareNetworkSpecifier.Builder
```

Configure the port number which will be used to create a connection over this link. This configuration should only be done on the server device, e.g. the device creating the `https://developer.android.com/reference/kotlin/java/net/ServerSocket.html#`.

Notes:

- The server device must be the Publisher device!
- The port information can only be specified on secure links, specified using `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)`

| Parameters ||
|---|---|
| `port` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): A positive integer indicating the port to be used for communication. Value is between 0 and 65535 inclusive |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |

### setPskPassphrase

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setPskPassphrase(pskPassphrase: String): WifiAwareNetworkSpecifier.Builder
```

Configure the PSK Passphrase for the Wi-Fi Aware connection being requested. This method is optional - if not called, then an Open (unencrypted) connection will be created. Note: Use `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)` to avoid interoperability issues when devices support different cipher suites by explicitly specifying a cipher suite as opposed to relying on a default cipher suite. `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareDataPathSecurityConfig.Builder#Builder(kotlin.Int)`

| Parameters ||
|---|---|
| `pskPassphrase` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): The (optional) passphrase to be used to encrypt the link. Use the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(kotlin.ByteArray)` to specify a PMK. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |

### setTransportProtocol

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setTransportProtocol(transportProtocol: Int): WifiAwareNetworkSpecifier.Builder
```

Configure the transport protocol which will be used to create a connection over this link. This configuration should only be done on the server device, e.g. the device creating the `https://developer.android.com/reference/kotlin/java/net/ServerSocket.html#` for TCP.

Notes:

- The server device must be the Publisher device!
- The transport protocol information can only be specified on secure links, specified using `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)`.

The transport protocol number is assigned by the Internet Assigned Numbers Authority (IANA) https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml.

| Parameters ||
|---|---|
| `transportProtocol` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The transport protocol to be used for communication. Value is between 0 and 255 inclusive |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` | the current `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#` builder, enabling chaining of builder methods. This value cannot be `null`. |