Repository navigation
FCM token handling on depersonalization
Supported on Android since version 16.3.0
This page explains what the SDK does with the Firebase Cloud Messaging (FCM) token when an installation is depersonalized or repersonalized, and how to opt out of it if your application manages the FCM token lifecycle by itself.
- Default behavior
- When to let the application manage the FCM token
- Enabling app-managed FCM token lifecycle
- What changes when enabled
- Responsibilities of the application
By default, after a successful depersonalization, the SDK resets the FCM token:
- it deletes the current token by calling
FirebaseMessaging.deleteToken(), - it requests a new token by calling
FirebaseMessaging.getToken(), - the new token is reported to Infobip, so the installation is no longer reachable via the previous token.
This is a privacy measure: a token that belonged to a previously logged-in user can't be used to deliver messages to the device anymore.
The SDK can also force a new token during repersonalization, when the push registration of the installation is no longer valid on the server side and there is no user data to restore.
Personalize with force depersonalization doesn't reset the FCM token. The installation is depersonalized on the server as part of the personalize request, and the SDK only performs its internal depersonalization cleanup, so the token stays the same regardless of the option described below.
Resetting the token affects every component of the app that relies on the same FCM token, not only the Infobip SDK. You may want to disable it if:
- your application (or another push provider used alongside Infobip, see custom FirebaseMessagingService) manages the FCM token itself and doesn't expect it to be replaced,
- your application depersonalizes often as part of its regular flow (for example, on user logout or when switching between In-app chat conversations), and the token change disrupts push or chat functionality.
Use withAppManagedFcmTokenLifecycle(true) when initializing the SDK. The option is disabled by default.
MobileMessaging.Builder(application)
.withAppManagedFcmTokenLifecycle(true)
.build()expand to see Java code
new MobileMessaging.Builder(application)
.withAppManagedFcmTokenLifecycle(true)
.build();The value is applied on every build() call. If you remove the builder option (or pass false), the default behavior is restored on the next SDK initialization.
| Scenario | Default | With withAppManagedFcmTokenLifecycle(true)
|
|---|---|---|
| Depersonalization completed | Token is deleted and a new one is requested | Token is not deleted nor requested |
| Personalize with force depersonalization | Token is not reset | Token is not reset (unchanged) |
| Repersonalization without user data (push registration invalidated on server) | New token is requested | Token is not requested |
| SDK internal depersonalization cleanup (user data, primary flag, etc.) | Performed | Performed |
New token received via MobileMessagingFirebaseService.onNewToken()
|
Processed and reported | Processed and reported |
| Application code change | Token is deleted | Token is deleted (unchanged) |
| Push service type change on SDK init | Token is reset | Token is reset (unchanged) |
When the option is enabled, the FCM token keeps being used by the installation after depersonalization. If you need a new token, for example to make sure that messages targeted to the previous user can't reach the device, you have to rotate it yourself.
Calling
FirebaseMessaging.getToken()doesn't triggeronNewToken()while the token stays the same. When your application obtains or rotates the token by itself, make sure it is passed to the SDK, so the SDK can (re)register it:MobileMessagingFirebaseService.onNewToken(context, token)
If the push registration of the installation is invalidated on the server side (for example, because FCM no longer accepts the token), the SDK won't request a new token during repersonalization. The installation stays unregistered for push messages until a new FCM token reaches the SDK via
MobileMessagingFirebaseService.onNewToken(). This happens automatically when Firebase issues a new token. If your application rotates the token by itself (deleteToken()+getToken()), pass the new token viaMobileMessagingFirebaseService.onNewToken(context, token). Passing back the same token won't restore push delivery.
If you use a custom FirebaseMessagingService, keep forwarding new tokens to MobileMessagingFirebaseService.onNewToken() from your onNewToken() implementation, as before.
If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue.