Reputation: 95
I was following some tutorials (seen below) on how to connect Firebase to the Xamarin Android app to use Push Notifications. My team already had it working but after making iOS work and going back to Android Push notifications, I noticed that it had issues.
Here is the part with issues:
private string GetFirebaseInstanceId()
{
FirebaseApp.InitializeApp(this);
var FCMToken = FirebaseInstanceId.Instance.Token;
if (string.IsNullOrEmpty(FCMToken))
{
return null;
}
Log.Debug(Tag, $"FCM Registration Token: {FCMToken}");
return FCMToken;
}
When trying to get the token, I get this error "Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process {packageName}. Make sure to call FirebaseApp.initializeApp(Context) first."
That is why I added FirebaseApp.InitializeApp(this) before trying to get the token, but it made no difference. I have also tried doing this in the Spash activity and Main activity, but it did not fix the issue.
I have also made sure that the build action of google-services.json is GoogleServicesJson.
As for the code changes that I made, here are some of notable ones I think might be relevant:
I checked the history of the file containing the snipped above and it the particular method wasn't changed.
Here some tutorials that I followed:
What can I do to properly retrieve the FCM registration token?
Upvotes: 3
Views: 3294
Reputation: 95
Surprisingly enough, I mainly had to undo some of my pending changes that I made to fix the issue, then clean and build the solution. I also added FirebaseApp.InitializeApp(this)
in the Main Activity.
Upvotes: 2