Alessandro
Alessandro

Reputation: 3760

Firebase token refresh

Firebase documentation clearly states that FirebaseInstanceIdService should be implemented to access refreshed token and that manual registration is not required anymore, since the library cares for all the process.

Problem is that onTokenRefresh is only called once, and if something goes wrong in the process of transferring it to my server, application has to wait until next refresh or do a complete uninstall/reinstall.

Could I apply the same logic as previous GCM implementations? That is, on every start of my application I access token using FirebaseInstanceId.getInstance().getToken() and sent it to my server, not caring if it has already been sent. Same thing is done in onTokenRefresh.

Does this approach have any pitfall?

Upvotes: 8

Views: 9325

Answers (2)

Keith Holliday
Keith Holliday

Reputation: 1732

Also, it seems you can call this function from outside of the service

FirebaseInstanceId.getInstance().getToken();

Upvotes: 12

Gaurav
Gaurav

Reputation: 3783

What I suggest that at first time when you get TOKEN stored it locally (may be in shared pref) and

make one flag initialize it as a false

and then try to send TOKEN to your server it sent successfully turn flag ti true, and no need to send again.

Upvotes: 3

Related Questions