FCM demo app not working on Android 8.0/8.1

GerryHGerryH USMember ✭✭✭

I am trying to run this sample app:

https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows

And get the error

Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.xamarin.fcmexample.
Make sure to call FirebaseApp.initializeApp(Context) first. occurred

So I added the call

FirebaseApp.InitializeApp(this);

at the end of the OnCreate, removed the bin/obj folders, rebuild and re-deployed (multiple times) but the exception will not go away. Is there a Xamarin demo app for Android 8.0/8.1 that can receive FCM notifications without crashing?

Tagged:

Best Answer

  • GerryHGerryH US ✭✭✭
    Accepted Answer

    I'm going to close this and start a new topic

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    I have tested the sample app of the link you post, and the sample could been built normally , and been deployed to my device (Google Pixel Android 8.1) without crashing.
    This is just a code sample, if we want to receive FCM notifications, we need to acquire the necessary credentials to use Google's servers. In the sample link , we can see the following note

    Before you can use this sample, you must acquire the necessary credentials to use Google's servers; this process is explained in Firebase Cloud Messaging. In particular, you must download google-services.json from the Firebase Console (this file contains your credentials) and add it to the app project, replacing the dummy google-services.json that comes with this sample.

    You could try to follow Firebase Cloud Messaging to achieve yourself FCM notifications.
    Of course , when we create our own app, we can use the key code of the sample app.

    Note: when you download the google-services.json file from project console, and make sure to set the Build Action of "GoogleServicesJson" to GoogleServicesJson, just as follows.

    Hope it can help you.

  • GerryHGerryH USMember ✭✭✭
    edited March 8

    I already did all that. I created a new google app to match the Firebase sample (same package name, application name) and now the sample runs without errors at least. [So the error is very misleading about what the problem actually is.]

    Anyway, I can now get a token and subscribe. But Google can seem to see my app:

    That never finishes. So I can't get to the firebase console to send a test notification

  • GerryHGerryH USMember ✭✭✭
    Accepted Answer

    I'm going to close this and start a new topic

Sign In or Register to comment.