# PrimarySession

# PrimarySession

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession "View this page in Java")

<br />

```
@RequiresApi(value = 26) interface PrimarySession
```

<br />

*** ** * ** ***

When a Session becomes shared with one or more devices, this interface represents the Primary device (the Session owner).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                            ### Public functions                                                                                                                                                                                                                                                                                                                                                                                                                             ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `suspend `[Unit](https://developer.android.com/reference/kotlin/kotlin/Unit)                                                                                                                                                  | [broadcastToSecondaries](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#broadcastToSecondaries(kotlin.ByteArray))`(bytes: `[ByteArray](https://developer.android.com/reference/kotlin/kotlin/ByteArray)`)` Enqueues`bytes`to be sent to all connected secondaries on their associated[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection).                                                                                                                                                       |
| [ListenableFuture](https://developer.android.com/reference/kotlin/com/google/common/util/concurrent/ListenableFuture)`<`[Void](https://developer.android.com/reference/kotlin/java/lang/Void)`?>`                             | [broadcastToSecondariesFuture](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#broadcastToSecondariesFuture(kotlin.ByteArray))`(bytes: `[ByteArray](https://developer.android.com/reference/kotlin/kotlin/ByteArray)`)` Java-compatible version of[broadcastToSecondaries](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#broadcastToSecondaries(kotlin.ByteArray)).                                                                                                                                                            |
| `suspend `[Unit](https://developer.android.com/reference/kotlin/kotlin/Unit)                                                                                                                                                  | [destroyPrimarySessionAndStopSharing](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#destroyPrimarySessionAndStopSharing())`()` Ends the shared experience that this PrimarySession is currently leading.                                                                                                                                                                                                                                                                                                                                                                             |
| [ListenableFuture](https://developer.android.com/reference/kotlin/com/google/common/util/concurrent/ListenableFuture)`<`[Void](https://developer.android.com/reference/kotlin/java/lang/Void)`?>`                             | [destroyPrimarySessionAndStopSharingFuture](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#destroyPrimarySessionAndStopSharingFuture())`()` Java-compatible version of[destroyPrimarySessionAndStopSharing](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#destroyPrimarySessionAndStopSharing()).                                                                                                                                                                                                                             |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit)                                                                                                                                                            | [disableSessionDiscovery](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#disableSessionDiscovery())`()` Disallows new participants to find and join the session.                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit)                                                                                                                                                            | [enableSessionDiscovery](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#enableSessionDiscovery())`()` Enables new participants to find and join the session.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)                                                                                     | [getSecondaryRemoteConnectionForParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#getSecondaryRemoteConnectionForParticipant(com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` secondary: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant) `)` Returns the[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)for`secondary`.                                                          |
| [List](https://developer.android.com/reference/kotlin/kotlin/collections/List)`<`[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)`>` | [getSecondaryRemoteConnections](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#getSecondaryRemoteConnections())`()` Returns a list containing the[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)instances for all secondaries related to this session.                                                                                                                                                                                                                                      |
| [Boolean](https://developer.android.com/reference/kotlin/kotlin/Boolean)                                                                                                                                                      | [isSessionDiscoveryEnabled](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#isSessionDiscoveryEnabled())`()` Checks whether session discovery is currently enabled.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `suspend `[Unit](https://developer.android.com/reference/kotlin/kotlin/Unit)                                                                                                                                                  | [removeSecondaryFromSession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#removeSecondaryFromSession(com.google.ambient.crossdevice.sessions.SessionParticipant))`(secondary: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant)`)` Removes the given participant from this session.                                                                                                                                                                                                                  |
| [ListenableFuture](https://developer.android.com/reference/kotlin/com/google/common/util/concurrent/ListenableFuture)`<`[Void](https://developer.android.com/reference/kotlin/java/lang/Void)`?>`                             | [removeSecondaryFromSessionFuture](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#removeSecondaryFromSessionFuture(com.google.ambient.crossdevice.sessions.SessionParticipant))`(secondary: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant)`)` Java-compatible version of[removeSecondaryFromSession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#removeSecondaryFromSession(com.google.ambient.crossdevice.sessions.SessionParticipant)). |

|                                                                                                                                                                                                                                        ### Public properties                                                                                                                                                                                                                                         ||
|---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId) | [sessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#sessionId()) The[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)this[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)belongs to. |

## Public functions

### broadcastToSecondaries

```
suspend fun broadcastToSecondaries(bytes: ByteArray): Unit
```

Enqueues`bytes`to be sent to all connected secondaries on their associated[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection).  

|                                                                                                                            Parameters                                                                                                                            ||
|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `bytes: `[ByteArray](https://developer.android.com/reference/kotlin/kotlin/ByteArray) | The bytes to be sent across the[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection). |

|                                                                                                                                                                                       Throws                                                                                                                                                                                       ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | if this[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### broadcastToSecondariesFuture

```
fun broadcastToSecondariesFuture(bytes: ByteArray): ListenableFuture<Void?>
```

Java-compatible version of[broadcastToSecondaries](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#broadcastToSecondaries(kotlin.ByteArray)).  

### destroyPrimarySessionAndStopSharing

```
suspend fun destroyPrimarySessionAndStopSharing(): Unit
```

Ends the shared experience that this PrimarySession is currently leading. Once`destroyPrimarySessionAndStopSharing`is called, all other methods will throw[SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException)when called.

On the secondary side, each secondary will be notified with[SecondarySessionStateCallback.onSecondarySessionCleanup](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SecondarySessionStateCallback#onSecondarySessionCleanup(com.google.ambient.crossdevice.sessions.SessionId)).  

|                                                                                                                                                                                     Throws                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### destroyPrimarySessionAndStopSharingFuture

```
fun destroyPrimarySessionAndStopSharingFuture(): ListenableFuture<Void?>
```

Java-compatible version of[destroyPrimarySessionAndStopSharing](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#destroyPrimarySessionAndStopSharing()).  

### disableSessionDiscovery

```
fun disableSessionDiscovery(): Unit
```

Disallows new participants to find and join the session.  

|                                                                                                                                                                                     Throws                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### enableSessionDiscovery

```
fun enableSessionDiscovery(): Unit
```

Enables new participants to find and join the session. This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is notified of new participants joining the session via[PrimarySessionStateCallback.onParticipantJoined](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onParticipantJoined(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionParticipant)). New participants are disabled by default.  

|                                                                                                                                                                                     Throws                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### getSecondaryRemoteConnectionForParticipant

```
fun getSecondaryRemoteConnectionForParticipant(
    secondary: SessionParticipant
): SessionRemoteConnection
```

Returns the[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)for`secondary`.  

|                                                                                                                                                                                                        Throws                                                                                                                                                                                                        ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | if this[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid or the`secondary`is not connected. |

### getSecondaryRemoteConnections

```
fun getSecondaryRemoteConnections(): List<SessionRemoteConnection>
```

Returns a list containing the[SessionRemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionRemoteConnection)instances for all secondaries related to this session.  

|                                                                                                                                                                                       Throws                                                                                                                                                                                       ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | if this[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### isSessionDiscoveryEnabled

```
fun isSessionDiscoveryEnabled(): Boolean
```

Checks whether session discovery is currently enabled.  

|                                                                                                                                                                                     Throws                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### removeSecondaryFromSession

```
suspend fun removeSecondaryFromSession(secondary: SessionParticipant): Unit
```

Removes the given participant from this session. On the secondary side, the secondary will be notified with[SecondarySessionStateCallback.onSecondarySessionCleanup](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SecondarySessionStateCallback#onSecondarySessionCleanup(com.google.ambient.crossdevice.sessions.SessionId)).  

|                                                                                Parameters                                                                                ||
|----------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `secondary: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant) | The participant to remove. |

|                                                                                                                                                                                     Throws                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `com.google.ambient.crossdevice.sessions.SessionException: `[com.google.ambient.crossdevice.sessions.SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException) | This[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### removeSecondaryFromSessionFuture

```
fun removeSecondaryFromSessionFuture(secondary: SessionParticipant): ListenableFuture<Void?>
```

Java-compatible version of[removeSecondaryFromSession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession#removeSecondaryFromSession(com.google.ambient.crossdevice.sessions.SessionParticipant)).

## Public properties

### sessionId

```
val sessionId: SessionId
```

The[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)this[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)belongs to.