# PrimarySession

# PrimarySession

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession "View this page in Kotlin")\|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 fields                                                                                                                                                                                                                                                                           ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId) | [sessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession#sessionId()) The[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)this[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)belongs to. |

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

## Public fields

### sessionId

```
abstract @NonNull SessionId sessionId
```

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

## Public methods

### broadcastToSecondaries

```
abstract void broadcastToSecondaries(@NonNull byte[] bytes)
```

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

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

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

### broadcastToSecondariesFuture

```
abstract @NonNull ListenableFuture<Void> broadcastToSecondariesFuture(@NonNull byte[] bytes)
```

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

### destroyPrimarySessionAndStopSharing

```
abstract void destroyPrimarySessionAndStopSharing()
```

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/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/com/google/ambient/crossdevice/sessions/SecondarySessionStateCallback#onSecondarySessionCleanup(com.google.ambient.crossdevice.sessions.SessionId)).  

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

### destroyPrimarySessionAndStopSharingFuture

```
abstract @NonNull ListenableFuture<Void> destroyPrimarySessionAndStopSharingFuture()
```

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

### disableSessionDiscovery

```
abstract void disableSessionDiscovery()
```

Disallows new participants to find and join the session.  

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

### enableSessionDiscovery

```
abstract void enableSessionDiscovery()
```

Enables new participants to find and join the session. This[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)is notified of new participants joining the session via[PrimarySessionStateCallback.onParticipantJoined](https://developer.android.com/reference/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](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionException)` com.google.ambient.crossdevice.sessions.SessionException` | This[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)is no longer valid. |

### getSecondaryRemoteConnectionForParticipant

```
abstract @NonNull SessionRemoteConnection getSecondaryRemoteConnectionForParticipant(
    @NonNull SessionParticipant secondary
)
```

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

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

### getSecondaryRemoteConnections

```
abstract @NonNull List<@NonNull SessionRemoteConnection> getSecondaryRemoteConnections()
```

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

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

### isSessionDiscoveryEnabled

```
abstract boolean isSessionDiscoveryEnabled()
```

Checks whether session discovery is currently enabled.  

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

### removeSecondaryFromSession

```
abstract void removeSecondaryFromSession(@NonNull SessionParticipant secondary)
```

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

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

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

### removeSecondaryFromSessionFuture

```
abstract @NonNull ListenableFuture<Void> removeSecondaryFromSessionFuture(@NonNull SessionParticipant secondary)
```

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