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

# PublishDiscoverySession

*** ** * ** ***

```
open class PublishDiscoverySession : DiscoverySession
```

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

A class representing a Aware publish session. Created when `https://developer.android.com/reference/kotlin/android/net/wifi/aware/WifiAwareSession#publish(android.net.wifi.aware.PublishConfig,%20android.net.wifi.aware.DiscoverySessionCallback,%20android.os.Handler)` is called and a discovery session is created and returned in `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPublishStarted(android.net.wifi.aware.PublishDiscoverySession)`. See baseline functionality of all discovery sessions in `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession`. This object allows updating an existing/running publish discovery session using `https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession#updatePublish(android.net.wifi.aware.PublishConfig)`.

## Summary

| Public methods ||
|---|---|
| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession#acceptDataPathRequest(android.net.wifi.aware.PeerHandle,%20android.net.wifi.aware.AwareDataPathRequest)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, request: https://developer.android.com/reference/kotlin/android/net/wifi/aware/AwareDataPathRequest)` Accept a Wi-Fi Aware data path request to create a connection with the target peer. |
| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession#rejectDataPathRequest(android.net.wifi.aware.PeerHandle)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle)` Reject a Wi-Fi Aware data path request received from peer. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishDiscoverySession#updatePublish(android.net.wifi.aware.PublishConfig)(publishConfig: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishConfig)` Re-configure the currently active publish session. |

| Inherited functions ||
|---|---|
| From class `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#acceptPairingRequest(kotlin.Int,%20android.net.wifi.aware.PeerHandle,%20kotlin.String,%20kotlin.Int,%20kotlin.String)(requestId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, peerDeviceAlias: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, cipherSuite: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, password: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?)` 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/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20kotlin.Int)` When the Aware Pairing setup is finished, both sides will receive `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupSucceeded(android.net.wifi.aware.PeerHandle,%20kotlin.String)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/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). 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/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onSessionTerminated()`. <br /> | | `https://developer.android.com/reference/kotlin/android/net/NetworkSpecifier.html#!` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierOpen(android.net.wifi.aware.PeerHandle)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle)` Create a `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#setNetworkSpecifier(android.net.NetworkSpecifier)` for an unencrypted 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`. 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/kotlin/android/net/wifi/aware/WifiAwareSession#createNetworkSpecifierOpen(kotlin.Int,%20kotlin.ByteArray)` 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/kotlin/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle,%20kotlin.String)` API. <br /> | | `https://developer.android.com/reference/kotlin/android/net/NetworkSpecifier.html#!` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#createNetworkSpecifierPassphrase(android.net.wifi.aware.PeerHandle,%20kotlin.String)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, passphrase: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Create a `https://developer.android.com/reference/kotlin/android/net/NetworkRequest.Builder.html#setNetworkSpecifier(android.net.NetworkSpecifier)` for an encrypted 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`. 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/kotlin/android/net/wifi/aware/WifiAwareSession#createNetworkSpecifierPassphrase(kotlin.Int,%20kotlin.ByteArray,%20kotlin.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 /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/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. 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 /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#initiateBootstrappingRequest(android.net.wifi.aware.PeerHandle,%20kotlin.Int)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, method: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` 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/kotlin/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/kotlin/android/net/wifi/aware/AwarePairingConfig.Builder#setBootstrappingMethods(kotlin.Int)` When the Aware Bootstrapping setup finished, both side will receive `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onBootstrappingSucceeded(android.net.wifi.aware.PeerHandle,%20kotlin.Int)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#initiateBootstrappingRequest(android.net.wifi.aware.PeerHandle,%20kotlin.Int,%20kotlin.ByteArray)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, method: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, message: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)` 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/kotlin/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/kotlin/android/net/wifi/aware/AwarePairingConfig.Builder#setBootstrappingMethods(kotlin.Int)` When the Aware Bootstrapping setup finished, both side will receive `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onBootstrappingSucceeded(android.net.wifi.aware.PeerHandle,%20kotlin.Int)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#initiatePairingRequest(android.net.wifi.aware.PeerHandle,%20kotlin.String,%20kotlin.Int,%20kotlin.String)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, peerDeviceAlias: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, cipherSuite: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, password: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?)` 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/kotlin/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/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20kotlin.Int)`. When the Aware Pairing setup is finished, both sides will receive `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupSucceeded(android.net.wifi.aware.PeerHandle,%20kotlin.String)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#rejectPairingRequest(kotlin.Int,%20android.net.wifi.aware.PeerHandle)(requestId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle)` Reject a Wi-Fi Aware Pairing setup request received from peer. This is the response to the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onPairingSetupRequestReceived(android.net.wifi.aware.PeerHandle,%20kotlin.Int)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#releaseDataPath(android.net.wifi.aware.PeerHandle)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/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/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onDataPathDisconnected(android.net.wifi.aware.PeerHandle)` will be called when the datapath is disconnected. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySession#sendMessage(android.net.wifi.aware.PeerHandle,%20kotlin.Int,%20kotlin.ByteArray)(peerHandle: https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle, messageId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, message: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html?)` 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/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onServiceDiscovered(android.net.wifi.aware.PeerHandle,%20kotlin.ByteArray,%20kotlin.collections.MutableList)` event. Aware messages are not guaranteed delivery. Callbacks on `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback` indicate message was transmitted successfully, `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onMessageSendSucceeded(kotlin.Int)`, or transmission failed (possibly after several retries) - `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onMessageSendFailed(kotlin.Int)`. The peer will get a callback indicating a message was received using `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onMessageReceived(android.net.wifi.aware.PeerHandle,%20kotlin.ByteArray)`. <br /> | ||

## Public methods

### acceptDataPathRequest

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

```
open fun acceptDataPathRequest(
    peerHandle: PeerHandle, 
    request: AwareDataPathRequest
): Boolean
```

Accept a Wi-Fi Aware data path request to create a connection with the target peer. The Aware data path request should be done in the context of a discovery session - after a `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onDataPathRequestReceived(android.net.wifi.aware.PeerHandle)` event is received. When the Aware data path setup succeeds, both side will receive `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onDataPathConnected(android.net.wifi.aware.PeerHandle,%20android.net.wifi.aware.WifiAwareNetworkInfo)`. Otherwise `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onDataPathRequestFailed(android.net.wifi.aware.PeerHandle,%20kotlin.Int)` will be called.

| Parameters ||
|---|---|
| `peerHandle` | [PeerHandle](https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle): The peer's handle for the data path request. This value cannot be `null`. |
| `request` | [AwareDataPathRequest](https://developer.android.com/reference/kotlin/android/net/wifi/aware/AwareDataPathRequest): The data path request. This value cannot be `null`. |

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | true if framework accept the data path request successfully and start negotiation, false otherwise. |

### rejectDataPathRequest

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

```
open fun rejectDataPathRequest(peerHandle: PeerHandle): Boolean
```

Reject a Wi-Fi Aware data path request received from peer. This is the response to the `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onDataPathRequestReceived(android.net.wifi.aware.PeerHandle)`

| Parameters ||
|---|---|
| `peerHandle` | [PeerHandle](https://developer.android.com/reference/kotlin/android/net/wifi/aware/PeerHandle): The peer's handle for the data path request. This value cannot be `null`. |

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | true if the data path is rejected successfully, false otherwise. |

### updatePublish

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

```
open fun updatePublish(publishConfig: PublishConfig): Unit
```

Re-configure the currently active publish session. The `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback` is not replaced - the same listener used at creation is still used. The results of the configuration are returned using `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback`:

- `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onSessionConfigUpdated()`: configuration update succeeded.
- `https://developer.android.com/reference/kotlin/android/net/wifi/aware/DiscoverySessionCallback#onSessionConfigFailed()`: configuration update failed. The publish discovery session is still running using its previous configuration (i.e. update failure does not terminate the session).

<br />

| Parameters ||
|---|---|
| `publishConfig` | [PublishConfig](https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishConfig): The new discovery publish session configuration (`https://developer.android.com/reference/kotlin/android/net/wifi/aware/PublishConfig`). This value cannot be `null`. |