Sessions
@RequiresApi(value = 26) interface Sessions
Entry-point for creating and interacting with Sessions. Create a client by calling Sessions.create
.
Summary
Nested types |
|
---|---|
Sessions.Companion |
Public methods
createSession
abstract @NonNull SessionId createSession(ApplicationSessionTag applicationSessionTag)
Creates a Session which can be be transferred to or shared with another device. Returns the SessionId
associated with that Session.
Parameters | |
---|---|
ApplicationSessionTag applicationSessionTag |
A client-defined concept that optionally describes the high level type of experience for a Session within an app. |
getReceivingSession
abstract @NonNull ReceivingSession getReceivingSession(
@NonNull Intent intent,
@NonNull ReceivingSessionStateCallback callback
)
Receives a ReceivingSession
to transfer a Session to this device. Should be called from receiving device after app is launched by D2DI with an intent specified by the originating device.
App should pass the intent
it was launched with as a parameter.
Throws | |
---|---|
com.google.ambient.crossdevice.sessions.SessionException com.google.ambient.crossdevice.sessions.SessionException |
if unable to return a |
getReceivingSessionFuture
abstract @NonNull ListenableFuture<@NonNull ReceivingSession> getReceivingSessionFuture(
@NonNull Intent intent,
@NonNull ReceivingSessionStateCallback callback
)
Java-compatible version of getReceivingSession
.
getSecondarySession
abstract @NonNull SecondarySession getSecondarySession(
@NonNull Intent intent,
@NonNull SecondarySessionStateCallback callback
)
Receives a SecondarySession
to join a Session from this device. Should be called from receiving device after app is launched by D2DI with an intent specified by the originating device.
App should pass the intent
it was launched with as a parameter.
Throws | |
---|---|
com.google.ambient.crossdevice.sessions.SessionException com.google.ambient.crossdevice.sessions.SessionException |
if unable to return a |
getSecondarySessionFuture
abstract @NonNull ListenableFuture<@NonNull SecondarySession> getSecondarySessionFuture(
@NonNull Intent intent,
@NonNull SecondarySessionStateCallback callback
)
Java-compatible version of getSecondarySession
.
registerActivityResultCaller
abstract void registerActivityResultCaller(
@NonNull ActivityResultCaller activityResultCaller
)
Registers an ActivityResultCaller
to enable Sessions to show available devices via Discovery's device launcher.
removeSession
abstract void removeSession(@NonNull SessionId sessionId)
Removes a Session so that it can no longer be discovered by other devices requesting transfer or share. If remove fails, a SessionException
will be thrown.
This will cancel any ongoing requests for transfer/share ( SessionStateCallback.onTransferFailure, SessionStateCallback.onShareFailure). This will terminate any active shared sessions (Primary and Secondaries will be cleaned up - PrimarySessionStateCallback.onPrimarySessionCleanup
, SecondarySessionStateCallback.onSecondarySessionCleanup
).
removeSessionFuture
abstract @NonNull ListenableFuture<Void> removeSessionFuture(@NonNull SessionId sessionId)
Java-compatible version of removeSession
.
shareSession
abstract @NonNull PrimarySession shareSession(
@NonNull SessionId sessionId,
@NonNull StartComponentRequest startComponentRequest,
@NonNull List<@NonNull DeviceFilter> deviceFilters,
@NonNull PrimarySessionStateCallback callback
)
Invites another device to join a Session currently running on the device this function is called on.
Opens a dialog that searches for compatible, trusted devices. When the user selects a specific device, the receiving app on that device will receive the request to join the session via StartComponentRequest
and can begin initialization (see SecondarySession
). StartComponentRequest
must contain an action and a user-visible reason for the request, and can optionally contain extras.
If the share cannot be initiated, a SessionException
will be thrown.
If the receiving app is ready to accept the share request, PrimarySessionStateCallback.onParticipantJoined
is triggered. Otherwise, PrimarySessionStateCallback.onShareFailureWithParticipant
is triggered.
Once devices are selected, PrimarySessionStateCallback.onShareInitiated
will be called to inform the application of the number of potential participants.
shareSessionFuture
abstract @NonNull ListenableFuture<@NonNull PrimarySession> shareSessionFuture(
@NonNull SessionId sessionId,
@NonNull StartComponentRequest startComponentRequest,
@NonNull List<@NonNull DeviceFilter> deviceFilters,
@NonNull PrimarySessionStateCallback callback
)
Java-compatible version of shareSession
.
transferSession
abstract @NonNull OriginatingSession transferSession(
@NonNull SessionId sessionId,
@NonNull StartComponentRequest startComponentRequest,
@NonNull List<@NonNull DeviceFilter> deviceFilters,
@NonNull OriginatingSessionStateCallback callback
)
Transfers a Session from the device this function is called on to another.
Opens a window that searches for compatible, trusted devices. When the user selects a specific device, the receiving app on that device will receive the request to transfer via StartComponentRequest
and can begin initialization (see ReceivingSession
). StartComponentRequest
must contain an action and a user-visible reason for the request, and can optionally contain extras.
If transfer cannot be initiated, a SessionException
will be thrown.
If receiving app is ready to accept the transfer, OriginatingSessionStateCallback.onConnected
is triggered. Otherwise, OriginatingSessionStateCallback.onTransferFailure
is triggered.
transferSessionFuture
abstract @NonNull ListenableFuture<@NonNull OriginatingSession> transferSessionFuture(
@NonNull SessionId sessionId,
@NonNull StartComponentRequest startComponentRequest,
@NonNull List<@NonNull DeviceFilter> deviceFilters,
@NonNull OriginatingSessionStateCallback callback
)
Java-compatible version of transferSession
.