# Print output for @column tags ?> DiscoverySessionCallback - Android SDK | Android Developers

Most visited

Recently visited

DiscoverySessionCallback

public class DiscoverySessionCallback
extends Object

java.lang.Object
   ↳ android.net.wifi.aware.DiscoverySessionCallback


Base class for Aware session events callbacks. Should be extended by applications wanting notifications. The callbacks are set when a publish or subscribe session is created using WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler).

A single callback is set at session creation - it cannot be replaced.

Summary

Public constructors

DiscoverySessionCallback()

Public methods

void onMessageReceived(PeerHandle peerHandle, byte[] message)

Called when a message is received from a discovery session peer - in response to the peer's DiscoverySession#sendMessage(PeerHandle, int, byte[]).

void onMessageSendFailed(int messageId)

Called when message transmission initiated with DiscoverySession#sendMessage(PeerHandle, int, byte[]) fails.

void onMessageSendSucceeded(int messageId)

Called in response to DiscoverySession#sendMessage(PeerHandle, int, byte[]) when a message is transmitted successfully - i.e.

void onPublishStarted(PublishDiscoverySession session)

Called when a publish operation is started successfully in response to a WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) operation.

void onServiceDiscovered(PeerHandle peerHandle, byte[] serviceSpecificInfo, List<byte[]> matchFilter)

Called when a discovery (publish or subscribe) operation results in a service discovery.

void onServiceDiscoveredWithinRange(PeerHandle peerHandle, byte[] serviceSpecificInfo, List<byte[]> matchFilter, int distanceMm)

Called when a discovery (publish or subscribe) operation results in a service discovery.

void onServiceLost(PeerHandle peerHandle, int reason)

Called when the discovered service is not available.

void onSessionConfigFailed()

Called when a publish or subscribe discovery session cannot be created: WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler), or when a configuration update fails: PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

void onSessionConfigUpdated()

Called when a publish or subscribe discovery session configuration update request succeeds.

void onSessionTerminated()

Called when a discovery session (publish or subscribe) terminates.

void onSubscribeStarted(SubscribeDiscoverySession session)

Called when a subscribe operation is started successfully in response to a WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler) operation.

Inherited methods

Public constructors

DiscoverySessionCallback

public DiscoverySessionCallback ()

Public methods

onMessageReceived

public void onMessageReceived (PeerHandle peerHandle, 
                byte[] message)

Called when a message is received from a discovery session peer - in response to the peer's DiscoverySession#sendMessage(PeerHandle, int, byte[]).

Parameters
peerHandle PeerHandle: An opaque handle to the peer matching our discovery operation.

message byte: A byte array containing the message.

onMessageSendFailed

public void onMessageSendFailed (int messageId)

Called when message transmission initiated with DiscoverySession#sendMessage(PeerHandle, int, byte[]) fails. E.g. when no ACK is received from the peer.

Note that either this callback or DiscoverySessionCallback#onMessageSendSucceeded(int) will be received - never both.

Parameters
messageId int: The arbitrary message ID specified when sending the message.

onMessageSendSucceeded

public void onMessageSendSucceeded (int messageId)

Called in response to DiscoverySession#sendMessage(PeerHandle, int, byte[]) when a message is transmitted successfully - i.e. when it was received successfully by the peer (corresponds to an ACK being received).

Note that either this callback or DiscoverySessionCallback#onMessageSendFailed(int) will be received - never both.

Parameters
messageId int: The arbitrary message ID specified when sending the message.

onPublishStarted

public void onPublishStarted (PublishDiscoverySession session)

Called when a publish operation is started successfully in response to a WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) operation.

Parameters
session PublishDiscoverySession: The PublishDiscoverySession used to control the discovery session. This value cannot be null.

onServiceDiscovered

public void onServiceDiscovered (PeerHandle peerHandle, 
                byte[] serviceSpecificInfo, 
                List<byte[]> matchFilter)

Called when a discovery (publish or subscribe) operation results in a service discovery.

Note that this method and onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle, byte[], java.util.List, int) may be called multiple times per service discovery.

Parameters
peerHandle PeerHandle: An opaque handle to the peer matching our discovery operation.

serviceSpecificInfo byte: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.

matchFilter List: The filter which resulted in this service discovery. For PublishConfig#PUBLISH_TYPE_UNSOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PublishConfig#PUBLISH_TYPE_SOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_ACTIVE discovery sessions this is the subscriber's match filter.

onServiceDiscoveredWithinRange

public void onServiceDiscoveredWithinRange (PeerHandle peerHandle, 
                byte[] serviceSpecificInfo, 
                List<byte[]> matchFilter, 
                int distanceMm)

Called when a discovery (publish or subscribe) operation results in a service discovery. Called when a Subscribe service was configured with a range requirement SubscribeConfig.Builder#setMinDistanceMm(int) and/or SubscribeConfig.Builder#setMaxDistanceMm(int) and the Publish service was configured with PublishConfig.Builder#setRangingEnabled(boolean).

If either Publisher or Subscriber does not enable Ranging, or if Ranging is temporarily disabled by the underlying device, service discovery proceeds without ranging and the onServiceDiscovered(android.net.wifi.aware.PeerHandle, byte[], java.util.List) is called.

Note that this method and onServiceDiscovered(android.net.wifi.aware.PeerHandle, byte[], java.util.List) may be called multiple times per service discovery.

Parameters
peerHandle PeerHandle: An opaque handle to the peer matching our discovery operation.

serviceSpecificInfo byte: The service specific information (arbitrary byte array) provided by the peer as part of its discovery configuration.

matchFilter List: The filter which resulted in this service discovery. For PublishConfig#PUBLISH_TYPE_UNSOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PublishConfig#PUBLISH_TYPE_SOLICITED, SubscribeConfig#SUBSCRIBE_TYPE_ACTIVE discovery sessions this is the subscriber's match filter.

distanceMm int: The measured distance to the Publisher in mm. Note: the measured distance may be negative for very close devices.

onServiceLost

public void onServiceLost (PeerHandle peerHandle, 
                int reason)

Called when the discovered service is not available. All further operations on this discovery session will fail. If the service is available again, onServiceDiscovered(android.net.wifi.aware.PeerHandle, byte[], java.util.List) or onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle, byte[], java.util.List, int) will be called.

Parameters
peerHandle PeerHandle: An opaque handle to the peer matching our discovery operation. This value cannot be null.

reason int: Discovered service lost reason code. One of WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE, WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN

onSessionConfigFailed

public void onSessionConfigFailed ()

Called when a publish or subscribe discovery session cannot be created: WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler), or when a configuration update fails: PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

For discovery session updates failure leaves the session running with its previous configuration - the discovery session is not terminated.

onSessionConfigUpdated

public void onSessionConfigUpdated ()

Called when a publish or subscribe discovery session configuration update request succeeds. Called in response to PublishDiscoverySession#updatePublish(PublishConfig) or SubscribeDiscoverySession#updateSubscribe(SubscribeConfig).

onSessionTerminated

public void onSessionTerminated ()

Called when a discovery session (publish or subscribe) terminates. Termination may be due to user-request (either directly through DiscoverySession#close() or application-specified expiration, e.g. PublishConfig.Builder#setTtlSec(int) or SubscribeConfig.Builder#setTtlSec(int)).

onSubscribeStarted

public void onSubscribeStarted (SubscribeDiscoverySession session)

Called when a subscribe operation is started successfully in response to a WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler) operation.

Parameters
session SubscribeDiscoverySession: The SubscribeDiscoverySession used to control the discovery session. This value cannot be null.