Reputation: 3437
I have followed this documentation and use multiple Firebase projects which are dynamically switched on login. As a result, I had to remove the google-services
plugin and the google-services.json
and set the configuration programmatically with FirebaseApp.initializeApp
. Everything works great so far, but when the app is killed completely and receives a notification, there is an error and the notification is not received:
E/AndroidRuntime: FATAL EXCEPTION: Firebase-NotificationMessageHandler
Process: com.example.app, PID: 8005
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
at com.google.firebase.messaging.zzo.zza(com.google.firebase:firebase-messaging@@20.1.0:120)
at com.google.firebase.messaging.zzo.zza(com.google.firebase:firebase-messaging@@20.1.0:1)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.1.0:50)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.1.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
at java.lang.Thread.run(Thread.java:764)
In all other situations I receive the notifications accordingly. With the google-services
plugin and the google-services.json
I can receive messages by FCM even when the app is killed, but that's not an option, because I can't switch Firebase projects dynamically using the google-services
plugin.
I always initialize the FirebaseApp as the default app: FirebaseApp.initializeApp(context, configuration)
Any hints on how to solve this?
Upvotes: 2
Views: 396
Reputation: 62391
As per documentation,
Notification Message - FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys and an optional data payload of custom key-value pairs.
Data Message - Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
Here is the full article for Test FCM Notification with POSTMAN!
Upvotes: 0
Reputation: 1018
You should call FirebaseApp.initializeApp(context, configuration) in onCreate() of Application
Upvotes: 0
Reputation: 3437
Using data messages
instead of notification messages
fixed the issue. I can now dynamically switch Firebase projects and receive notifications, even when the app was killed / closed.
More information: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
Upvotes: 1