# Participant

# Participant

*** ** * ** ***

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

<br />

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

<br />

*** ** * ** ***

An opaque handle that represents a participant in a cross device experience. This participant is expected to be passed back to other Cross device SDK components to identify the desired participant.

Participants are not stable across experiences. If the user starts another experience by selecting the same receiving device, the resulting[Participant](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant)instance will still be different.

This class is not thread safe.

## Summary

|                                                                                                                                                                                                                                                                 ### Public fields                                                                                                                                                                                                                                                                  ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)`>` | [connections](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#connections()) The list of connections connected to this participant. |
| `abstract @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)                                                                                                                                                                                                | [displayName](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#displayName()) A user-friendly name of the selected device.           |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                   ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `default @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[Result](https://developer.android.com/reference/kotlin/Result)`<@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)`>`                                                 | [acceptConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#acceptConnection(kotlin.String))`(@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName)` Accepts an incoming connection from a remote device.                                                                                                                          |
| `abstract @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[ListenableFuture](https://developer.android.com/reference/com/google/common/util/concurrent/ListenableFuture)`<@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)`>` | [acceptConnectionFuture](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#acceptConnectionFuture(kotlin.String))`(@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName)` Java-compatible version of[acceptConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#acceptConnection(kotlin.String)). |
| `abstract void`                                                                                                                                                                                                                                                                                                                                                                                                            | [close](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#close())`()` Closes this participant and all the associated[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)s.                                                                                                                                                                                                            |
| `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)`>`                                                                                                                                            | [closeFuture](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#closeFuture())`()` Java-compatible version of[close](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#close()).                                                                                                                                                                                                                                         |
| `default @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[Result](https://developer.android.com/reference/kotlin/Result)`<@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)`>`                                                 | [openConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#openConnection(kotlin.String))`(@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName)` Returns a remote channel to send and receive messages.                                                                                                                            |
| `abstract @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[ListenableFuture](https://developer.android.com/reference/com/google/common/util/concurrent/ListenableFuture)`<@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)`>` | [openConnectionFuture](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#openConnectionFuture(kotlin.String))`(@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName)` Java-compatible version of[openConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#openConnection(kotlin.String)).         |

## Public fields

### connections

```
abstract @NonNull List<@NonNull RemoteConnection> connections
```

The list of connections connected to this participant. This list includes both connections opened and accepted.  

### displayName

```
abstract @NonNull CharSequence displayName
```

A user-friendly name of the selected device. This is the same name that the user saw in the device picker, for example, "Ryan's Pixel 6".

## Public methods

### acceptConnection

```
default @NonNull Result<@NonNull RemoteConnection> acceptConnection(@NonNull String channelName)
```

Accepts an incoming connection from a remote device.

This function completes as soon as the connection channel is created, even if there are no listeners registered for this connection on the receiving device yet. Messages can be sent as soon as the connection is created, but they may be queued until a listener is registered.

It is expected that this call will fail for a fraction of cases due to circumstances outside of the application and system's control, such as poor signal strength or wireless interference. Therefore, this method returns a[Result](https://developer.android.com/reference/kotlin/Result)and callers should always check and handle the failure cases.

If the connection is not created successfully within an implementation-defined timeout (typically on the order of tens of seconds), the result will fail with the code[ConnectionsException.TIMEOUT](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionsException.Companion#TIMEOUT()).

Callers should close the connection after using it by calling either[RemoteConnection.close](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection#close(kotlin.String))or[Participant.close](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#close()).  

|                                                                                                                                                                                                                                                                                                                   Parameters                                                                                                                                                                                                                                                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName` | A string identifying the channel. This string must be the same on this device and the remote device indicated by`participant`for the messages to be received successfully. The tuple (callingApp, participant, channelName) must be unique - trying to create a channel with the same name, from the same application, to the same remote device will result in an[IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException). |

### acceptConnectionFuture

```
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> acceptConnectionFuture(@NonNull String channelName)
```

Java-compatible version of[acceptConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#acceptConnection(kotlin.String)).  

### close

```
abstract void close()
```

Closes this participant and all the associated[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)s. This participant should not be used after calling this method.  

### closeFuture

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

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

### openConnection

```
default @NonNull Result<@NonNull RemoteConnection> openConnection(@NonNull String channelName)
```

Returns a remote channel to send and receive messages.

This function completes as soon as the connection channel is created, even if there are no listeners registered for this connection on the receiving device yet. Messages can be sent as soon as the connection is created, but they may be queued until a listener is registered.

It is expected that this call will fail for a fraction of cases due to circumstances outside of the application and system's control, such as poor signal strength or wireless interference. Therefore, this method returns a[Result](https://developer.android.com/reference/kotlin/Result)and callers should always check and handle the failure cases.

If the connection is not created successfully within an implementation-defined timeout (typically on the order of tens of seconds), the result will fail with the code[ConnectionsException.TIMEOUT](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionsException.Companion#TIMEOUT()).

Callers should close the connection after using it by calling either[RemoteConnection.close](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection#close(kotlin.String))or[Participant.close](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#close()).  

|                                                                                                                                                                                                                                                                                                                              Parameters                                                                                                                                                                                                                                                                                                                              ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[String](https://developer.android.com/reference/java/lang/String)` channelName` | A string identifying the channel. This string must be the same on this device and the remote device from which this`participant`was provided for the messages to be received successfully. The tuple (callingApp, participant, channelName) must be unique - trying to create a channel with the same name, from the same application, to the same participant device will result in an[IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException). |

### openConnectionFuture

```
abstract @NonNull ListenableFuture<@NonNull RemoteConnection> openConnectionFuture(@NonNull String channelName)
```

Java-compatible version of[openConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/Participant#openConnection(kotlin.String)).