Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#inhmethods)

# WifiAwareNetworkSpecifier.Builder

*** ** * ** ***

` public static final class WifiAwareNetworkSpecifier.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.wifi.aware.WifiAwareNetworkSpecifier.Builder |

<br />

*** ** * ** ***

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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.DiscoverySession,%20android.net.wifi.aware.PeerHandle)(https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession discoverySession, https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle) ` Create a builder for `https://developer.android.com/reference/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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.PublishDiscoverySession)(https://developer.android.com/reference/android/net/wifi/aware/PublishDiscoverySession publishDiscoverySession) ` Create a builder for `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier` used in requests to set up a Wi-Fi Aware connection. |

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

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### Builder

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

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

Create a builder for `https://developer.android.com/reference/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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#Builder(android.net.wifi.aware.PublishDiscoverySession)`.

<br />

| Parameters ||
|---|---|
| `discoverySession` | `DiscoverySession`: A Wi-Fi Aware discovery session in whose context the connection is created. This value cannot be `null`. <br /> |
| `peerHandle` | `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/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.PeerHandle,%20byte[],%20java.util.List<byte[]>)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])`. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (PublishDiscoverySession publishDiscoverySession)
```

Create a builder for `https://developer.android.com/reference/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/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/android/net/ConnectivityManager#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/android/net/ConnectivityManager.NetworkCallback#onAvailable(android.net.Network)`. Calling `https://developer.android.com/reference/android/net/ConnectivityManager#unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback)` will terminate all connections.

<br />

| Parameters ||
|---|---|
| `publishDiscoverySession` | `PublishDiscoverySession`: This value cannot be `null`. <br /> |

## Public methods

### build

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

```
public WifiAwareNetworkSpecifier build ()
```

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

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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(java.lang.String)` or `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(byte[])` builder methods.

<br />

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

### setChannelFrequencyMhz

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

```
public WifiAwareNetworkSpecifier.Builder setChannelFrequencyMhz (int channelInMhz, 
                boolean required)
```

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/android/net/wifi/aware/WifiAwareManager#isSetChannelOnDataPathSupported()` is true, otherwise the set channelInMhz will be ignored.

<br />

| Parameters ||
|---|---|
| `channelInMhz` | `int`: Channel frequency in Mhz. Value is 0 or greater <br /> |
| `required` | `boolean`: 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. <br /> |

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

### setDataPathSecurityConfig

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

```
public WifiAwareNetworkSpecifier.Builder setDataPathSecurityConfig (WifiAwareDataPathSecurityConfig securityConfig)
```

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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(byte[])` and `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(java.lang.String)`.

<br />

| Parameters ||
|---|---|
| `securityConfig` | `WifiAwareDataPathSecurityConfig`: The (optional) security config to be used to encrypt the link. This value cannot be `null`. <br /> |

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

### setPmk

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

```
public WifiAwareNetworkSpecifier.Builder setPmk (byte[] pmk)
```

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

<br />

| Parameters ||
|---|---|
| `pmk` | `byte`: 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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPskPassphrase(java.lang.String)` to specify a Passphrase. This value cannot be `null`. <br /> |

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

### setPort

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

```
public WifiAwareNetworkSpecifier.Builder setPort (int port)
```

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/java/net/ServerSocket`.

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/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setDataPathSecurityConfig(android.net.wifi.aware.WifiAwareDataPathSecurityConfig)`

<br />

<br />

| Parameters ||
|---|---|
| `port` | `int`: A positive integer indicating the port to be used for communication. Value is between 0 and 65535 inclusive <br /> |

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

### setPskPassphrase

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

```
public WifiAwareNetworkSpecifier.Builder setPskPassphrase (String pskPassphrase)
```

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/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/android/net/wifi/aware/WifiAwareDataPathSecurityConfig.Builder#Builder(int)`

<br />

| Parameters ||
|---|---|
| `pskPassphrase` | `String`: The (optional) passphrase to be used to encrypt the link. Use the `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder#setPmk(byte[])` to specify a PMK. This value cannot be `null`. <br /> |

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

### setTransportProtocol

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

```
public WifiAwareNetworkSpecifier.Builder setTransportProtocol (int transportProtocol)
```

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/java/net/ServerSocket` 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/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.

<br />

<br />

| Parameters ||
|---|---|
| `transportProtocol` | `int`: The transport protocol to be used for communication. Value is between 0 and 255 inclusive <br /> |

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