Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#inhmethods)

# DiscoverySession

*** ** * ** ***

` public class DiscoverySession `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/lang/AutoCloseable `

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

Known direct subclasses [PublishDiscoverySession](https://developer.android.com/reference/android/net/wifi/aware/PublishDiscoverySession), [SubscribeDiscoverySession](https://developer.android.com/reference/android/net/wifi/aware/SubscribeDiscoverySession) [PublishDiscoverySession](https://developer.android.com/reference/android/net/wifi/aware/PublishDiscoverySession) A class representing a Aware publish session. [SubscribeDiscoverySession](https://developer.android.com/reference/android/net/wifi/aware/SubscribeDiscoverySession) A class representing a Aware subscribe session.   

*** ** * ** ***

A class representing a single publish or subscribe Aware session. This object will not be created directly - only its child classes are available: `https://developer.android.com/reference/android/net/wifi/aware/PublishDiscoverySession` and `https://developer.android.com/reference/android/net/wifi/aware/SubscribeDiscoverySession`. This class provides functionality common to both publish and subscribe discovery sessions:

- Sending messages: `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#sendMessage(android.net.wifi.aware.PeerHandle,%20int,%20byte[])` method.
- Creating a network-specifier when requesting a Aware connection using `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder`.

The `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#close()` method must be called to destroy discovery sessions once they are no longer needed.

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#acceptPairingRequest(int,%20android.net.wifi.aware.PeerHandle,%20java.lang.String,%20int,%20java.lang.String)(int requestId, https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, https://developer.android.com/reference/java/lang/String peerDeviceAlias, int cipherSuite, https://developer.android.com/reference/java/lang/String password) ` Accept and respond to a Wi-Fi Aware Pairing setup request received from peer. |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#close()() ` Destroy the publish or subscribe session - free any resources, and stop transmitting packets on-air (for an active session) or listening for matches (for a passive session). |
| ` https://developer.android.com/reference/android/net/NetworkSpecifier` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle)(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle) ` *This method was deprecated in API level 29. Use the replacement `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder`.* |
| ` https://developer.android.com/reference/android/net/NetworkSpecifier` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle,%20java.lang.String)(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, https://developer.android.com/reference/java/lang/String passphrase) ` *This method was deprecated in API level 29. Use the replacement `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder`.* |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#initiateBootstrappingRequest(android.net.wifi.aware.PeerHandle,%20int,%20byte[])(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, int method, byte[] message) ` Defined as per Wi-Fi Aware specifications version 4.0 Section 7.6.4.1. |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#initiateBootstrappingRequest(android.net.wifi.aware.PeerHandle,%20int)(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, int method) ` Defined as per Wi-Fi Aware specifications version 4.0 Section 7.6.4.1. |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#initiatePairingRequest(android.net.wifi.aware.PeerHandle,%20java.lang.String,%20int,%20java.lang.String)(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, https://developer.android.com/reference/java/lang/String peerDeviceAlias, int cipherSuite, https://developer.android.com/reference/java/lang/String password) ` Initiate a Wi-Fi Aware Pairing setup request to create a pairing with the target peer. |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#rejectPairingRequest(int,%20android.net.wifi.aware.PeerHandle)(int requestId, https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle) ` Reject a Wi-Fi Aware Pairing setup request received from peer. |
| ` boolean` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#releaseDataPath(android.net.wifi.aware.PeerHandle)(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle) ` Release the Aware data path to the specified peer. |
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#sendMessage(android.net.wifi.aware.PeerHandle,%20int,%20byte[])(https://developer.android.com/reference/android/net/wifi/aware/PeerHandle peerHandle, int messageId, byte[] message) ` Sends a message to the specified destination. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### 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*.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Public methods

### acceptPairingRequest

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

```
public void acceptPairingRequest (int requestId, 
                PeerHandle peerHandle, 
                String peerDeviceAlias, 
                int cipherSuite, 
                String password)
```

Accept and respond to a Wi-Fi Aware Pairing setup request received from peer. This is the response to the `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20int)` When the Aware Pairing setup is finished, both sides will receive `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupSucceeded(android.net.wifi.aware.PeerHandle,%20java.lang.String)`

<br />

| Parameters ||
|---|---|
| `requestId` | `int`: Id to identify the received pairing session, obtained by `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20int)` <br /> |
| `peerHandle` | `PeerHandle`: The peer's handle for the pairing request. Must be a result of a `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])` events. This value cannot be `null`. <br /> |
| `peerDeviceAlias` | `String`: The alias of paired device set by caller, will help caller to identify the paired device. This value cannot be `null`. <br /> |
| `cipherSuite` | `int`: The cipher suite to be used to encrypt the link. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/net/wifi/aware/Characteristics#WIFI_AWARE_CIPHER_SUITE_NCS_PK_PASN_128` - `https://developer.android.com/reference/android/net/wifi/aware/Characteristics#WIFI_AWARE_CIPHER_SUITE_NCS_PK_PASN_256` |
| `password` | `String`: The password is used for the pairing setup. If set to empty or null, opportunistic pairing will be used. <br /> |

### close

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

```
public void close ()
```

Destroy the publish or subscribe session - free any resources, and stop transmitting packets on-air (for an active session) or listening for matches (for a passive session). The session may not be used for any additional operations after its destruction.

This operation must be done on a session which is no longer needed. Otherwise system resources will continue to be utilized until the application exits. The only exception is a session for which we received a termination callback, `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onSessionTerminated()`.

<br />

### createNetworkSpecifierOpen

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

```
public NetworkSpecifier createNetworkSpecifierOpen (PeerHandle peerHandle)
```

<br />

**This method was deprecated in API level 29.**   

Use the replacement `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder`.

Create a `https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(android.net.NetworkSpecifier)` for an unencrypted 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`.

This method should be used when setting up a connection with a peer discovered through Aware discovery or communication (in such scenarios the MAC address of the peer is shielded by an opaque peer ID handle). If an Aware connection is needed to a peer discovered using other OOB (out-of-band) mechanism then use the alternative `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareSession#createNetworkSpecifierOpen(int,%20byte[])` method - which uses the peer's MAC address.

Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR and a Publisher is a RESPONDER.

To set up an encrypted link use the `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle,%20java.lang.String)` API.

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle 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[])`. On a RESPONDER this value is used to gate the acceptance of a connection request from only that peer. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkSpecifier` | 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\]. <br /> |

### createNetworkSpecifierPassphrase

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

```
public NetworkSpecifier createNetworkSpecifierPassphrase (PeerHandle peerHandle, 
                String passphrase)
```

<br />

**This method was deprecated in API level 29.**   

Use the replacement `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareNetworkSpecifier.Builder`.

Create a `https://developer.android.com/reference/android/net/NetworkRequest.Builder#setNetworkSpecifier(android.net.NetworkSpecifier)` for an encrypted 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`.

This method should be used when setting up a connection with a peer discovered through Aware discovery or communication (in such scenarios the MAC address of the peer is shielded by an opaque peer ID handle). If an Aware connection is needed to a peer discovered using other OOB (out-of-band) mechanism then use the alternative `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareSession#createNetworkSpecifierPassphrase(int,%20byte[],%20java.lang.String)` method - which uses the peer's MAC address.

Note: per the Wi-Fi Aware specification the roles are fixed - a Subscriber is an INITIATOR and a Publisher is a RESPONDER.

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle 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[])`. On a RESPONDER this value is used to gate the acceptance of a connection request from only that peer. This value cannot be `null`. <br /> |
| `passphrase` | `String`: The passphrase to be used to encrypt the link. The PMK is generated from the passphrase. Use the `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle)` API to specify an open (unencrypted) link. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/NetworkSpecifier` | 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\]. <br /> |

### initiateBootstrappingRequest

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

```
public void initiateBootstrappingRequest (PeerHandle peerHandle, 
                int method, 
                byte[] message)
```

Defined as per Wi-Fi Aware specifications version 4.0 Section 7.6.4.1. Initiate a Wi-Fi Aware bootstrapping setup request to create a pairing with the target peer. The Aware bootstrapping request should be done in the context of a discovery session - after a publish/subscribe `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` event is received. The peer will check if the method can be fulfilled by `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig.Builder#setBootstrappingMethods(int)` When the Aware Bootstrapping setup finished, both side will receive `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onBootstrappingSucceeded(android.net.wifi.aware.PeerHandle,%20int)`

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle for the pairing request. Must be a result of an `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])` events. This value cannot be `null`. <br /> |
| `method` | `int`: one of the AwarePairingConfig#PAIRING_BOOTSTRAPPING_ values, should match one of the methods received from `https://developer.android.com/reference/android/net/wifi/aware/ServiceDiscoveryInfo#getPairingConfig()` `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#getBootstrappingMethods()` Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_OPPORTUNISTIC` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PIN_CODE_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PASSPHRASE_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_QR_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_NFC_TAG` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PIN_CODE_KEYPAD` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PASSPHRASE_KEYPAD` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_QR_SCAN` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_NFC_READER` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_SERVICE_MANAGED` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_SKIPPED` |
| `message` | `byte`: An arbitrary byte array which can be sent as service info in Service Descriptor Extension attribute (SDEA) - see Wi-Fi Aware specification 9.5.4.2 for more details. Recommnaded to use `https://developer.android.com/reference/android/net/wifi/aware/WifiAwareManager#createTxtRecordTlvBuffer(java.util.Map<java.lang.String,java.lang.String>)` to create key-value message in DNS-SD format. This value cannot be `null`. <br /> |

### initiateBootstrappingRequest

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

```
public void initiateBootstrappingRequest (PeerHandle peerHandle, 
                int method)
```

Defined as per Wi-Fi Aware specifications version 4.0 Section 7.6.4.1. Initiate a Wi-Fi Aware bootstrapping setup request to create a pairing with the target peer. The Aware bootstrapping request should be done in the context of a discovery session - after a publish/subscribe. `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` event is received. The peer will check if the method can be fulfilled by `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig.Builder#setBootstrappingMethods(int)` When the Aware Bootstrapping setup finished, both side will receive `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onBootstrappingSucceeded(android.net.wifi.aware.PeerHandle,%20int)`

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle for the pairing request. Must be a result of an `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])` events. This value cannot be `null`. <br /> |
| `method` | `int`: one of the AwarePairingConfig#PAIRING_BOOTSTRAPPING_ values, should match one of the methods received from `https://developer.android.com/reference/android/net/wifi/aware/ServiceDiscoveryInfo#getPairingConfig()` `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#getBootstrappingMethods()` Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_OPPORTUNISTIC` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PIN_CODE_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PASSPHRASE_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_QR_DISPLAY` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_NFC_TAG` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PIN_CODE_KEYPAD` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_PASSPHRASE_KEYPAD` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_QR_SCAN` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_NFC_READER` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_SERVICE_MANAGED` - `https://developer.android.com/reference/android/net/wifi/aware/AwarePairingConfig#PAIRING_BOOTSTRAPPING_SKIPPED` |

### initiatePairingRequest

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

```
public void initiatePairingRequest (PeerHandle peerHandle, 
                String peerDeviceAlias, 
                int cipherSuite, 
                String password)
```

Initiate a Wi-Fi Aware Pairing setup request to create a pairing with the target peer. The Aware pairing request should be done in the context of a discovery session - after a publish/subscribe `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` event is received. The peer will get a callback indicating a message was received using `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20int)`. When the Aware Pairing setup is finished, both sides will receive `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupSucceeded(android.net.wifi.aware.PeerHandle,%20java.lang.String)`

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle for the pairing request. Must be a result of a `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])` events. This value cannot be `null`. <br /> |
| `peerDeviceAlias` | `String`: The alias of paired device set by caller, will help caller to identify the paired device. This value cannot be `null`. <br /> |
| `cipherSuite` | `int`: The cipher suite to be used to encrypt the link. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/net/wifi/aware/Characteristics#WIFI_AWARE_CIPHER_SUITE_NCS_PK_PASN_128` - `https://developer.android.com/reference/android/net/wifi/aware/Characteristics#WIFI_AWARE_CIPHER_SUITE_NCS_PK_PASN_256` |
| `password` | `String`: The password used for the pairing setup. If set to empty or null, opportunistic pairing will be used. <br /> |

### rejectPairingRequest

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

```
public void rejectPairingRequest (int requestId, 
                PeerHandle peerHandle)
```

Reject a Wi-Fi Aware Pairing setup request received from peer. This is the response to the `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20int)`

<br />

| Parameters ||
|---|---|
| `requestId` | `int`: Id to identify the received pairing session, get by `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20int)` <br /> |
| `peerHandle` | `PeerHandle`: The peer's handle for the pairing request. Must be a result of a `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.ServiceDiscoveryInfo)` or `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])` events. This value cannot be `null`. <br /> |

### releaseDataPath

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

```
public boolean releaseDataPath (PeerHandle peerHandle)
```

Release the Aware data path to the specified peer. The datapath will be disconnected if no other applications are requesting it. `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onDataPathDisconnected(android.net.wifi.aware.PeerHandle)` will be called when the datapath is disconnected.

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle is used in `https://developer.android.com/reference/android/net/wifi/aware/PublishDiscoverySession#acceptDataPathRequest(android.net.wifi.aware.PeerHandle,%20android.net.wifi.aware.AwareDataPathRequest)` or `https://developer.android.com/reference/android/net/wifi/aware/SubscribeDiscoverySession#initiateDataPathRequest(android.net.wifi.aware.PeerHandle,%20android.net.wifi.aware.AwareDataPathRequest)` This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the data path is released successfully, false otherwise. <br /> |

### sendMessage

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

```
public void sendMessage (PeerHandle peerHandle, 
                int messageId, 
                byte[] message)
```

Sends a message to the specified destination. Aware messages are transmitted in the context of a discovery session - executed subsequent to a publish/subscribe `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.PeerHandle,%20byte[],%20java.util.List<byte[]>)` event.

Aware messages are not guaranteed delivery. Callbacks on `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback` indicate message was transmitted successfully, `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageSendSucceeded(int)`, or transmission failed (possibly after several retries) - `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageSendFailed(int)`.

The peer will get a callback indicating a message was received using `https://developer.android.com/reference/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20byte[])`.

<br />

| Parameters ||
|---|---|
| `peerHandle` | `PeerHandle`: The peer's handle for the message. Must be a result of an `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[])` events. This value cannot be `null`. <br /> |
| `messageId` | `int`: An arbitrary integer used by the caller to identify the message. The same integer ID will be returned in the callbacks indicating message send success or failure. The `messageId` is not used internally by the Aware service - it can be arbitrary and non-unique. <br /> |
| `message` | `byte`: The message to be transmitted. This value may be `null`. <br /> |

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the `finalize` method to dispose of system resources or to perform other cleanup.

The general contract of `finalize` is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The `finalize` method may take any action, including making this object available again to other threads; the usual purpose of `finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The `finalize` method of class `Object` performs no special action; it simply returns normally. Subclasses of `Object` may override this definition.

The Java programming language does not guarantee which thread will invoke the `finalize` method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the `finalize` method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The `finalize` method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the `finalize` method causes the finalization of this object to be halted, but is otherwise ignored.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |