# ConnectionReceiver

# ConnectionReceiver

*** ** * ** ***

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

<br />

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

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                             ### Public functions                                                                                                                                                                                                                                                                                                                                                                                                                                                             ||
|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onConnectionClosed](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/ConnectionReceiver#onConnectionClosed(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.Throwable,kotlin.String))`(` ` remoteConnection: `[RemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/RemoteConnection)`,` ` error: `[Throwable](https://developer.android.com/reference/kotlin/kotlin/Throwable)`?,` ` reason: `[String](https://developer.android.com/reference/kotlin/kotlin/String)`?` `)` Called when the[remoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/ConnectionReceiver#onConnectionClosed(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.Throwable,kotlin.String))is closed. |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onMessageReceived](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/ConnectionReceiver#onMessageReceived(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.ByteArray))`(remoteConnection: `[RemoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/RemoteConnection)`, payload: `[ByteArray](https://developer.android.com/reference/kotlin/kotlin/ByteArray)`)` Called when a message is received on the[remoteConnection](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/connections/ConnectionReceiver#onMessageReceived(com.google.ambient.crossdevice.connections.RemoteConnection,kotlin.ByteArray)).                                                                                                               |

## Public functions

### onConnectionClosed

```
fun onConnectionClosed(
    remoteConnection: RemoteConnection,
    error: Throwable? = null,
    reason: String? = null
): Unit
```

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

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

### onMessageReceived

```
fun onMessageReceived(remoteConnection: RemoteConnection, payload: ByteArray): Unit
```

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