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 publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or 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 sendMessage(PeerHandle, int, byte[]).

void onMessageSendFailed(int messageId)

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

void onMessageSendSucceeded(int messageId)

Called in response to 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 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 onSessionConfigFailed()

Called when a publish or subscribe discovery session cannot be created: publish(PublishConfig, DiscoverySessionCallback, android.os.Handler) or subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler), or when a configuration update fails: updatePublish(PublishConfig) or 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 subscribe(SubscribeConfig, DiscoverySessionCallback, android.os.Handler) operation.

Inherited methods

Public constructors

DiscoverySessionCallback

added in API level 26
DiscoverySessionCallback ()

Public methods

onMessageReceived

added in API level 26
void onMessageReceived (PeerHandle peerHandle, 
                byte[] message)

Called when a message is received from a discovery session peer - in response to the peer's 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

added in API level 26
void onMessageSendFailed (int messageId)

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

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

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

onMessageSendSucceeded

added in API level 26
void onMessageSendSucceeded (int messageId)

Called in response to 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 onMessageSendFailed(int) will be received - never both.

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

onPublishStarted

added in API level 26
void onPublishStarted (PublishDiscoverySession session)

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

Parameters
session PublishDiscoverySession: The PublishDiscoverySession used to control the discovery session.

This value must never be null.

onServiceDiscovered

added in API level 26
void onServiceDiscovered (PeerHandle peerHandle, 
                byte[] serviceSpecificInfo, 
                List<byte[]> matchFilter)

Called when a discovery (publish or subscribe) operation results in a 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 PUBLISH_TYPE_UNSOLICITED, SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PUBLISH_TYPE_SOLICITED, SUBSCRIBE_TYPE_ACTIVE discovery sessions this is the subscriber's match filter.

onServiceDiscoveredWithinRange

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 setMinDistanceMm(int) and/or setMaxDistanceMm(int) and the Publish service was configured with 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(PeerHandle, byte[], List) is called.

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 PUBLISH_TYPE_UNSOLICITED, SUBSCRIBE_TYPE_PASSIVE discovery sessions this is the publisher's match filter. For PUBLISH_TYPE_SOLICITED, 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.

onSessionConfigFailed

added in API level 26
void onSessionConfigFailed ()

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

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

onSessionConfigUpdated

added in API level 26
void onSessionConfigUpdated ()

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

onSessionTerminated

added in API level 26
void onSessionTerminated ()

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

onSubscribeStarted

added in API level 26
void onSubscribeStarted (SubscribeDiscoverySession session)

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

Parameters
session SubscribeDiscoverySession: The SubscribeDiscoverySession used to control the discovery session.

This value must never be null.