android - Unable to generate FCM token from dynamically instantiated Firebase -


our business logic requires instantiate firebase during runtime. fetch firebase credentials (app id, api key etc.) default firebase location after knowing user's public key , create firebase instance using credentials.

this means there 2 firebase instances used within app:

  1. the default "index" firebase gives credentials second
  2. the actual firebase intend use point forward

the second firebase initialised this:

firebaseapp app = firebaseapp.initializeapp(<context>, <options>, <app_label>); 

our problem traditional method of retrieving fcm token using firebaseinstanceidservice , ontokenrefresh() fails since ontokenrefresh() method called first firebase instance.

directly calling string token = firebaseinstanceid.getinstance(app).gettoken(); returns null never ready when called. have tried polling test if token generated @ point. no luck.

how can generate fcm token reliably firebase instance instantiated during runtime?

in general, traditional method of getting token (gettoken()) 1 refers main firebase instance. can called anywhere in app (but called in initial activity). return token associated sender id seen in google-services.json. possible return null if token still being generated. in cases that, ontokenrefresh() triggered upon generation.

however, if intend generate fcm registration token different firebase project, you'll have make use firebaseintsanceid.getinstance.gettoken(string authorizedentity, string scope), authorizedentity sender id of different firebase project , scope "fcm" (you can use firebasemessaging.instance_id_scope default).

in short, don't need specify firebase instance when generating token.

also see answers here , here.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -