-->

Firebase notification works even with no service o

2019-08-24 09:58发布

问题:

I implemented firebase into my app to use it's notification service a while back and it worked, and today decided to use it's key/value feature, but realized that no matter what I write in my class inherited from FirebaseMessagingService, nothing happens. So I decided to remove the my class for dubugging purposes, and I still got notifications. So I removed the firebase messaging service from the manifest, deleted the app cache and ran the project, but I still get notifications! The only way I can prevent notifications from coming is to remove the firebase dependency in gradle. What's happening here?

回答1:

Just read the documentation.

...

Ok, let's go: there are three kind of "notification" using Firebase: notification messages, data messages and messages with both notification and data. Each is received and handled differently by the system. Here you can see more information about message types (how there are built).

There are handled like that:

  • Notification message
    • App in foreground: onMessageReceived's implementation
    • App in background: system tray (system dispatch automatically notification) -> with or without service implementation (maybe your case, without code I can't know)
  • Data message
    • App in foreground: onMessageReceived's implementation
    • App in background: onMessageReceived's implementation
  • Message with both notification and data
    • App in foreground: onMessageReceived's implementation
    • App in background: system tray (notification) and in extras of the intent (data)

But without any code or notification information, I can't continue to help you. Until you provide some code example, I only think that you send a notification message, and so system automatically display a notification and there is no call to the service's onMessageReceived, it's normal.

If you want to "control" and decide if notification should be shown or not, just send data messages, and in your onMessageReceived implementation, create a notification with content and intent and notify it to the system (if you want it to be shown).