firebase / firebase/firebase-android-sdk

Using FCM notifications with data payloads leads to potentially confusing results

Open
#1,807 8 comments 7 reactions 1 assignee Claimed by @cpsloal View on GitHub
api: messaging type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

### [READ] Step 1: Are you in the right place?

Yes, your people might consider it is a feature request but to me this is clearly a bug due a bad architecture.

### [REQUIRED] Step 2: Describe your environment

* Android Studio version: any
* Firebase Component: FCM
* Component version: any

### [REQUIRED] Step 3: Describe the problem

#### Steps to reproduce:

When using FCM to push notifications to android devices, developpers need to deal with a 6 posible scenarios described in this table
https://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages

the simple fact of having a 6 scenario table for something simple like "push notification" should alread trig an 'alert' in any architect mind, but the thing gets worse when we think about the messages with data. they might be delivered to `onMessageReceived` and might be to the launcher intent.

so it automatically creates a scenario where the code will be duplicated, two classes will need to deal with same business logic. but this is not the end

follow my logic:
1- app is in background
2- fcm pushes a data+notification message
3- user sees the notification in system tray... and simple ignores it,
or even has that kind of notification set to NEVER SHOW on android settings

following this scenario the app WILL NEVER RECEIVE THE DATA FROM THAT NOTIFICATION. since the launcher intent from the notification tray will never be clicked

i dont know what kind of android restrictions lead the engineers decide for this such frankstein behavior but at first glance it could be easily fix

if the android-fcm SDK is able to send the data messages to `onMessageReceived` even during background time... why the mixed data+notification could not send the data part also to `onMessageReceived`?

imho everything could be sent to that method and this class could implement a very simple method allowing any developper to foward the notifications to system tray from the `onMessageReceived` method

this would avoid so much code replication and create a less franksteins behavior

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.