Skip to content

FirebaseMessagingService: onNewToken() for non-default FirebaseApp #5646

Open
@VictorColomb

Description

@VictorColomb

What feature would you like to see?

The FirebaseMessagingService.onNewToken(token: String) method is called when a FCM token is (re)generated, but only for the default FirebaseApp, as defined in FirebaseMessaging.invokeOnTokenRefresh.

A new method onNewToken(token: String, appName: String) could be added to the FirebaseMessagingService to handle token (re)generation for non-default FirebaseApp instances. This way the new overloaded method gets called on token generation for all FirebaseApp instances, allowing clients like me to handle/save the new token.

The current onNewToken could remain exclusive to the default app so as to not introduce breaking changes.

How would you use it?

I can see the two following use cases:

1/ Having two or more Firebase projects registered and being able to send notifications and messages from both.

2/ (My use case) I am working on an easy-to-use custom notification server, with the objective that anyone can host their own instance (e.g. private Nagios instance / home automation).
The Android app therefore needs to receive Firebase project parameters from the server and initialize a secondary FirebaseApp at runtime. Once initialized, this instance should be able to handle the entire FCM token lifecycle, the regeneration of which is a crutial step.

The current workaround I am using is storing the last known token in DataStore preferences and having a worker check whether is has changed every 24h. This potentially introduces a 24h period during which the device is unable to receive notifications and messages.

References

This limitation was already discussed in #2285, but was not the actual subject of the feature request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions