Firebase notification sometimes skip onMessageRece

2019-04-17 23:07发布

问题:

When I was using Parse from Facebook, I could test notification while in development (i.e. no app on the Play Store). But right now I am trying to implement Firebase into my app. My app is not published yet. I am done with android side implementation and am trying to send a notification from the Firebase console to my app. But my device never receives the notification. Why is that? I am targeting "All Users" because firebase does not have a version or any of my topics.

OKAY

So I did some more troubleshooting and here it is: my device is receiving notifications, but it's doing so weirdly:

  1. when the app is open and the user is interacting with it, the notification goes through the expected pathway of calling onMessageReceived.

  2. When the app is closed (not in recent apps either), the notification skips calling onMessageReceived and displays a notification in the status bar.

But then here is the log from FireBase when onMessageReceived is skipped

05-24 07:15:52.842  D/TimaKeyStoreProvider: TimaSignature is unavailable
05-24 07:15:52.842  D/ActivityThread: Added TimaKeyStore provider
05-24 07:15:53.102  D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
05-24 07:15:53.132  D/FirebaseApp: Initialized class com.google.firebase.iid.FirebaseInstanceId.
05-24 07:15:53.142  D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
05-24 07:15:53.222  I/FA: App measurement is starting up, version: 9080
05-24 07:15:53.222  I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-24 07:15:53.352  D/FirebaseApp: Initialized class com.google.android.gms.measurement.AppMeasurement.
05-24 07:15:53.352  I/FirebaseInitProvider: FirebaseApp initialization successful
05-24 07:15:53.372  D/AlgorithmsProvider: onCreate
05-24 07:15:53.452  I/FA: Tag Manager is not found and thus will not be used

回答1:

For the display-messages (messages with notification tag), it's the expected behaviour that the onMessageReceived only called when the app is on foreground.

If you want to use data-messages (message without notification tag), you can't do it via console (at least until this time). You have to manually create post request to FCM server. You can see that post request example from answer to this question How to handle notification when app in background in Firebase.