I am developing an App in Xamarin Android, for notifications I am using FCM the Pre-Release package: https://www.nuget.org/packages/Xamarin.Firebase.Messaging/
Now e
i'm manualy trying to initialize like this
var options = new FirebaseOptions.Builder()
.SetApplicationId("YOURAPPID")
.SetApiKey("YOURAPIKEY")
//.SetDatabaseUrl(Keys.Firebase.Database_Url) //i'M not using it
.SetGcmSenderId("YOURSENDERID")
//.SetStorageBucket(Keys.Firebase.StorageBucket)//i'M not using it
.Build();
try
{ //try to initilize firebase app to get token
FirebaseApp.InitializeApp(Forms.Context, options);//initializeto get token
}
catch
{ //if app already initialized it will throw exception, so get the previous active token and send to your server-database etc
var instanceId = FirebaseInstanceId.Instance;
var token = instanceId.Token;
Service.MyFirebaseMessagingService.RegisterForAndroid(token); //this method sends the token to my server app, you have to write your own
}
So when user opens the app, I'm trying to reinitialize the Firebase app. If it is already initalized it will throw an exception :) I'm taking the token there so it gives me the active registered token. If app is not initialized everything will work on smoothly and so your OnTokenRefresh method will be fired as expected. Hope this helps you.