I have made the Firebase Cloud Message Notification working even work through the Notification Hub from Azure. The time I can\'t receive the message is when I try to re-run
Android using Firebase Cloud Messaging not receiving message
As the GCM docs said :
An ID issued by the GCM connection servers to the client app that allows it to receive messages.
So only when the token is available, your app can receive message from GCM
.
How can an app get that token?
You could see the document :
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token.
The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh
Every time when you re-run the application in your device the token is changed, but as the document said, OnTokenRefresh
is only called when the system determines that the tokens need to be refreshed, it is needed for key rotation and to handle Instance ID changes due to :
You need to trigger OnTokenRefresh
method. You should first uninstall the app from the device, then reinstall the app and open it, the OnTokenRefresh
will be triggered and the token will be updated and your app could receive GCM
message again.