in new firebase, under notification, have mentioned developer can send notification particular device. that, in console asks fcm token. , how can token?
what exactly?
an fcm token, or commonly known registrationtoken
in google-cloud-messaging. described in gcm docs:
an id issued gcm connection servers client app allows receive messages. note registration tokens must kept secret.
how can token?
as per fcm docs:
on initial startup of app, fcm sdk generates registration token client app instance. if want target single devices or create device groups, you'll need access token.
you can access token's value extending firebaseinstanceidservice. make sure have added service manifest, call gettoken in context of ontokenrefresh, , log value shown:
@override public void ontokenrefresh() { // updated instanceid token. string refreshedtoken = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "refreshed token: " + refreshedtoken); // todo: implement method send registration app's servers. sendregistrationtoserver(refreshedtoken); }
the ontokenrefreshcallback fires whenever new token generated, calling gettoken in context ensures accessing current, available registration token. firebaseinstanceid.gettoken() returns null if token has not yet been generated.
after you've obtained token, can send app server , store using preferred method. see instance id api reference full detail on api.