onNewPushToken

Call when the push token for the app changes.

Flybuy can leverage Google's Firebase Cloud Messaging (FCM) to get updates about the status of an order. Since a device's push token can change, the Flybuy SDK needs to be informed when that occurs. To do so, override the FirebaseMessagingService.onNewToken() method as follows.

override fun onNewToken(token: String) {
FlyBuyCore.onNewPushToken(token)
}

Also, make sure to refresh the token when the user logs in/out. Here's examples of doing that.

FlyBuyCore.getInstance().customer.login(login.value ?: LoginInfo()) { customer, sdkError ->
handleSdkError(sdkError)
if (null != customer) {
FirebaseMessaging.getInstance().deleteToken()
}
}
FlyBuyCore.getInstance().customer.logout { sdkError ->
handleSdkError(sdkError)
FirebaseMessaging.getInstance().deleteToken()
}

The SDK should also be updated with the push token when the app starts. The following code snippet provides an example function that can be called from onCreate() in your activity.

private fun onNewPushToken() {
FirebaseMessaging.getInstance().token
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Timber.w(task.exception, "getInstanceId failed")
return@OnCompleteListener
}

// Get new Instance ID token
task.result?.let {
FlyBuyCore.onNewPushToken(it)
}
})
}