# ConnectionReceiver

# ConnectionReceiver

*** ** * ** ***

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

<br />

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

<br />

*** ** * ** ***

Receiver callback for a[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                             ||
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract void` | [onConnectionClosed](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onConnectionClosed(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.Throwable,kotlin.String))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)` remoteConnection,` ` `[Throwable](https://developer.android.com/reference/java/lang/Throwable)` error,` ` `[String](https://developer.android.com/reference/java/lang/String)` reason` `)` Called when the[remoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onConnectionClosed(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.Throwable,kotlin.String))is closed. |
| `abstract void` | [onMessageReceived](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onMessageReceived(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.ByteArray))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)` remoteConnection,` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` byte[] payload` `)` Called when a message is received on the[remoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onMessageReceived(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.ByteArray)).                                                                                |

## Public methods

### onConnectionClosed

```
abstract void onConnectionClosed(
    @NonNull RemoteConnection remoteConnection,
    Throwable error,
    String reason
)
```

Called when the[remoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onConnectionClosed(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.Throwable,kotlin.String))is closed.  

|                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                          ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[RemoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection)` remoteConnection` | The remote connection that is closed.                                                                                                                                                                                        |
| [Throwable](https://developer.android.com/reference/java/lang/Throwable)` error`                                                                                                                                               | The error causing the connection to be closed, or`null`if the connection was closed normally.                                                                                                                                |
| [String](https://developer.android.com/reference/java/lang/String)` reason`                                                                                                                                                    | The reason indicated by the remote end of the connection in their call to[RemoteConnection.close](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/RemoteConnection#close(kotlin.String)). |

### onMessageReceived

```
abstract void onMessageReceived(
    @NonNull RemoteConnection remoteConnection,
    @NonNull byte[] payload
)
```

Called when a message is received on the[remoteConnection](https://developer.android.com/reference/com/google/ambient/crossdevice/connections/ConnectionReceiver#onMessageReceived(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.ByteArray)).