provideDeviceToken

abstract suspend fun provideDeviceToken(context: Context, token: String): Result<String>

Stores the Firebase Cloud Messaging (FCM) device token for push notification registration.

Call this method from your FirebaseMessagingService.onNewToken override. The token is persisted locally and the registration call is deferred until the first network request (e.g., creating a conversation or sending a message). No action occurs if the same token has already been stored.

Unlike CoreClient.registerDevice, which makes the registration call to the server immediately, this static method only stores the token for later registration.

Example usage in a FirebaseMessagingService:

override fun onNewToken(token: String) {
super.onNewToken(token)
scope.launch {
CoreClient.provideDeviceToken(applicationContext, token)
}
}

Return

Result.Success containing the stored token, or Result.Error if storage fails.

Parameters

context

The application Context.

token

The FCM device token received from Firebase.

Samples

// Store the FCM token for push notification registration.
// Unlike CoreClient.registerDevice(), this does not make the registration
// call immediately. Instead, the token is persisted locally and the
// registration call is made on the first network request (e.g., creating
// a conversation or sending a message).
val fcmToken = "token-from-FirebaseMessaging.getInstance().token"
val result = CoreClient.provideDeviceToken(context, fcmToken)