Push Notification Token Updates

HYPR SDK for Android

HYPR uses Firebase as a push notification provider when authenticating users for web accounts. In some circumstances, the Firebase registration token can change, rendering the server unable to push notifications to the device.

To allow Android applications to automatically update the push notification token when required, app\commonlibraries\src\main\java\com\hypr\commonlibraries\HyprWrapper.kt includes the following interface:

 * Start action to update Push Token in all App Profiles that exist in the
 * Application. If there are websites registered on multiple RP Applications
 * across multiple RP Servers, then all of them will get the Push Token updated.
 * There is no UI Spinner for this operation on the SDK level.
 * @param activity  		Activity that is kicking off the action and handling the result
 * @param firebaseToken Push Token to update in the HYPR server

fun updateFirebaseTokenIfNeeded(activity: Activity, onCompletion: (isSuccess: Boolean, hyprStatusResult: HyprStatusResult?) -> Unit) {
  if (HyprApp.getDbAdapter().isUpdateFirebaseTokenNeeded(activity)) {
    val properties = HyprAppProperties(activity)
      HyprActions.getInstance().updatePushToken(activity, properties.firebaseToken, object : HyprActionCallbacks.HyprActionCallback {
      override fun onSuccess(statusResult: HyprStatusResult) {
        onCompletion(true, statusResult)

      override fun onFailure(statusResult: HyprStatusResult) {
        onCompletion(false, statusResult)

The \webaccountunlock module overrides the onNewToken method in the CustomFirebaseMessagingService class (\app\webaccountunlock\src\main\java\com\hypr\webaccountunlock), extending the FirebaseMessagingService class:

     * This is called when we generate a new registration token. The registration
     * token is used for determining to which device to send the push notification
    override fun onNewToken(token: String) {
        HyprPushNotificationAdapter.getInstance().onNewPushChannelId(applicationContext, token)

You must use a local flag to track whether or not a token refresh is needed. Check this flag in your App initialization sequence before making the updatePushToken interface call.