# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Methods | Inherited Methods

# WifiAwareSession

`public class WifiAwareSession`
`extends Object` `implements AutoCloseable`

java.lang.Object
↳ | android.net.wifi.aware.WifiAwareSession

This class represents a Wi-Fi Aware session - an attachment to the Wi-Fi Aware service through which the app can execute discovery operations.

## Summary

### Public methods
`void` | `close()` Destroy the Wi-Fi Aware service session and, if no other applications are attached to Aware, also disable Aware.
`NetworkSpecifier` | `createNetworkSpecifierOpen(int role, byte[] peer)` This method is deprecated. Please use in-band data-path setup, refer to `WifiAwareNetworkSpecifier.Builder`, `publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)` and `subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)`
`NetworkSpecifier` | `createNetworkSpecifierPassphrase(int role, byte[] peer, String passphrase)` This method is deprecated. Please use in-band data-path setup, refer to `WifiAwareNetworkSpecifier.Builder`, `publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)` and `subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)`
`void` | `publish(PublishConfig publishConfig, DiscoverySessionCallback callback, Handler handler)` Issue a request to the Aware service to create a new Aware publish discovery session, using the specified `publishConfig` configuration.
`void` | `subscribe(SubscribeConfig subscribeConfig, DiscoverySessionCallback callback, Handler handler)` Issue a request to the Aware service to create a new Aware subscribe discovery session, using the specified `subscribeConfig` configuration.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `java.lang.AutoCloseable`
`abstract void` | `close()` Closes this resource, relinquishing any underlying resources.

## Public methods

### close

    public void close ()

Destroy the Wi-Fi Aware service session and, if no other applications are attached to Aware, also disable Aware. This method destroys all outstanding operations - i.e. all publish and subscribes are terminated, and any outstanding data-links are shut-down. However, it is good practice to destroy these discovery sessions and connections explicitly before a session-wide destroy.

An application may re-attach after a destroy using `WifiAwareManager#attach(AttachCallback, Handler)` .

### createNetworkSpecifierOpen

    public NetworkSpecifier createNetworkSpecifierOpen (int role,
                    byte[] peer)

This method is deprecated.
Please use in-band data-path setup, refer to `WifiAwareNetworkSpecifier.Builder`, `publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)` and `subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)`

Create a `NetworkRequest.Builder.setNetworkSpecifier(NetworkSpecifier)` for an unencrypted WiFi Aware connection (link) to the specified peer. The `NetworkRequest.Builder.addTransportType(int)` should be set to `NetworkCapabilities.TRANSPORT_WIFI_AWARE`.

This API is targeted for applications which can obtain the peer MAC address using OOB (out-of-band) discovery. Aware discovery does not provide the MAC address of the peer - when using Aware discovery use the alternative network specifier method - `WifiAwareNetworkSpecifier.Builder`.

To set up an encrypted link use the `createNetworkSpecifierPassphrase(int, byte[], java.lang.String)` API.

Parameters
`role` | `int`: The role of this device: `WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR` or `WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_RESPONDER` Value is `WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR`, or `WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER`
`peer` | `byte`: The MAC address of the peer's Aware discovery interface. On a RESPONDER this value is used to gate the acceptance of a connection request from only that peer. This value cannot be `null`.

Returns
`NetworkSpecifier` | A `NetworkSpecifier` to be used to construct `NetworkRequest.Builder.setNetworkSpecifier(NetworkSpecifier)` to pass to `ConnectivityManager.requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback)` [or other varieties of that API].

### createNetworkSpecifierPassphrase

    public NetworkSpecifier createNetworkSpecifierPassphrase (int role,
                    byte[] peer,
                    String passphrase)

This method is deprecated.
Please use in-band data-path setup, refer to `WifiAwareNetworkSpecifier.Builder`, `publish(android.net.wifi.aware.PublishConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)` and `subscribe(android.net.wifi.aware.SubscribeConfig, android.net.wifi.aware.DiscoverySessionCallback, android.os.Handler)`

Create a `NetworkRequest.Builder.setNetworkSpecifier(NetworkSpecifier)` for an encrypted WiFi Aware connection (link) to the specified peer. The `NetworkRequest.Builder.addTransportType(int)` should be set to `NetworkCapabilities.TRANSPORT_WIFI_AWARE`.

This API is targeted for applications which can obtain the peer MAC address using OOB (out-of-band) discovery. Aware discovery does not provide the MAC address of the peer - when using Aware discovery use the alternative network specifier method - `WifiAwareNetworkSpecifier.Builder`.

Parameters
`role` | `int`: The role of this device: `WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_INITIATOR` or `WifiAwareManager#WIFI_AWARE_DATA_PATH_ROLE_RESPONDER` Value is `WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR`, or `WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER`
`peer` | `byte`: The MAC address of the peer's Aware discovery interface. On a RESPONDER this value is used to gate the acceptance of a connection request from only that peer. This value cannot be `null`.
`passphrase` | `String`: The passphrase to be used to encrypt the link. The PMK is generated from the passphrase. Use `createNetworkSpecifierOpen(int, byte[])` to specify an open (unencrypted) link. This value cannot be `null`.

Returns
`NetworkSpecifier` | A `NetworkSpecifier` to be used to construct `NetworkRequest.Builder.setNetworkSpecifier(NetworkSpecifier)` to pass to `ConnectivityManager.requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback)` [or other varieties of that API].

### publish

    public void publish (PublishConfig publishConfig,
                    DiscoverySessionCallback callback,
                    Handler handler)

Issue a request to the Aware service to create a new Aware publish discovery session, using the specified `publishConfig` configuration. The results of the publish operation are routed to the callbacks of `DiscoverySessionCallback`:

- `DiscoverySessionCallback#onPublishStarted( PublishDiscoverySession)` is called when the publish session is created and provides a handle to the session. Further operations on the publish session can be executed on that object.
- `DiscoverySessionCallback#onSessionConfigFailed()` is called if the publish operation failed.

Other results of the publish session operations will also be routed to callbacks on the `callback` object. The resulting publish session can be modified using `PublishDiscoverySession#updatePublish(PublishConfig)`.

The total count of currently available Wi-Fi Aware publish sessions is limited and is available via the `AwareResources#getAvailablePublishSessionsCount()` method.

An application must use the `DiscoverySession#close()` to terminate the publish discovery session once it isn't needed. This will free resources as well terminate any on-air transmissions.

The application must have the `Manifest.permission.ACCESS_FINE_LOCATION` permission to start a publish discovery session.

Parameters
`publishConfig` | `PublishConfig`: The `PublishConfig` specifying the configuration of the requested publish session. This value cannot be `null`.
`callback` | `DiscoverySessionCallback`: A `DiscoverySessionCallback` derived object to be used for session event callbacks. This value cannot be `null`.
`handler` | `Handler`: The Handler on whose thread to execute the callbacks of the `callback` object. If a null is provided then the application's main thread will be used. This value may be `null`.

### subscribe

    public void subscribe (SubscribeConfig subscribeConfig,
                    DiscoverySessionCallback callback,
                    Handler handler)

Issue a request to the Aware service to create a new Aware subscribe discovery session, using the specified `subscribeConfig` configuration. The results of the subscribe operation are routed to the callbacks of `DiscoverySessionCallback`:

- `DiscoverySessionCallback#onSubscribeStarted( SubscribeDiscoverySession)` is called when the subscribe session is created and provides a handle to the session. Further operations on the subscribe session can be executed on that object.
- `DiscoverySessionCallback#onSessionConfigFailed()` is called if the subscribe operation failed.

Other results of the subscribe session operations will also be routed to callbacks on the `callback` object. The resulting subscribe session can be modified using `SubscribeDiscoverySession#updateSubscribe(SubscribeConfig)`.

The total count of currently available Wi-Fi Aware subscribe sessions is limited and is available via the `AwareResources#getAvailableSubscribeSessionsCount()` method.

An application must use the `DiscoverySession#close()` to terminate the subscribe discovery session once it isn't needed. This will free resources as well terminate any on-air transmissions.

The application must have the `Manifest.permission.ACCESS_FINE_LOCATION` permission to start a subscribe discovery session.

Parameters
`subscribeConfig` | `SubscribeConfig`: The `SubscribeConfig` specifying the configuration of the requested subscribe session. This value cannot be `null`.
`callback` | `DiscoverySessionCallback`: A `DiscoverySessionCallback` derived object to be used for session event callbacks. This value cannot be `null`.
`handler` | `Handler`: The Handler on whose thread to execute the callbacks of the `callback` object. If a null is provided then the application's main thread will be used. This value may be `null`.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*