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?
Also, it seems you can call this function from outside of the service
FirebaseInstanceId.getInstance().getToken();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With