Register a device
A device must be registered before an Amazon Connect journey can deliver a notification to it. Registering stores the device's push token against the current user's profile identity, so your backend knows where to send messages.
Register with the FCM registration token
Obtain the token from Firebase Cloud Messaging and pass it to registerDevice:
import com.google.firebase.messaging.FirebaseMessagingimport kotlinx.coroutines.tasks.await
val token = FirebaseMessaging.getInstance().token.await()val result = client.registerDevice(token)Register again whenever FCM rotates the token, by calling registerDevice from your FirebaseMessagingService.onNewToken callback. Requesting notification permission and receiving messages remain your application's responsibility through Firebase; the client only registers the token with your backend.
The token is the only value you provide
The library resolves the remaining device fields for you:
| Field | Source |
|---|---|
deviceId | A stable identifier the library generates and persists per installation, shared with other Amplify libraries. |
platform | The platform string passed when creating the client. |
appVersion | The appVersion string passed when creating the client. |
channelType | The channelType passed when creating the client. Defaults to ChannelType.GCM. |
Registration is an idempotent operation keyed on deviceId, so calling registerDevice again with a new token updates the existing record rather than creating a second one.
The device belongs to the current identity
The registered device is stored against the principalId that your backend derives from the signed request, so a device always belongs to the identity that registered it. Your application never sends a user identifier, and one user cannot register a device against another user's profile.
Because the identity comes from Amazon Cognito identity pool credentials, registration works for guest users as well as signed-in users.
When to call registerDevice
Call registerDevice in these situations:
- After the user grants notification permission and the platform issues a push token.
- Whenever the platform rotates the token.
- After a user signs in, to move the device registration from the guest identity to the authenticated one. See Guest and authenticated users.
You do not need to call registerDevice on every application start. The registration persists until it is removed or the token changes.
Handle errors
registerDevice returns a Result that fails with a ConnectValidationException when the token is blank, or with a network, credentials, or service exception when the request cannot complete:
import com.amplifyframework.foundation.result.Result
when (val result = client.registerDevice(token)) { is Result.Success -> { /* device registered */ } is Result.Failure -> { /* inspect result.error */ }}Next steps
- Remove a device: de-register a device before signing a user out.