firebase / firebase/firebase-android-sdk

[messaging] Ability to change the notification before it's sent to the system tray

Open
#2,639 11 comments 74 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 9h
Merged PRs (30d)
31

Description

## What feature would you like to see?

Hi, is there anything on the roadmap to provide the ability to customise the notification before it's sent to the system tray. I'm a maintainer of [notifee](https://github.com/invertase/notifee), and we recently added support to do this with iOS, we'd love to be able to do it with Android too.

Currently, the only option there seems to be is to send data messages. A couple of issues with this method are that you need to send two different types of messages based on whether the device is android or iOS, and having to keep track of which platform the token is registered with.

In addition to platform-dependent code, there's also different background restrictions for data-only vs notification messages (ref [here](https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message)).

On iOS, you can alter the notification using a Notification Service Extension where you have a brief amount of time to modify the notification before it's displayed to the user. in addition to the flexibility that `message.apns.aps` object offers where you can add a categoryId, sound, threadId e.t.c.

One possible solution could be to allow [FirebaseMessagingService.onMessageReceived](https://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages) to be called for all app states, maybe a check somehow to see if the app does supports this, if not, default to handling with FCM? If this was possible, the one issue I do see with this, is that it could clash with other libraries like `FlutterFire` and `react-native-firebase` as you can only have one FirebaseMessagingService per app.

Another solution, which I think seems way easier and less intrusive is to have a separate service, like how iOS works, to alter the notification and nothing else.

I can see how this could be a big f/r, and maybe there's reasons that it's not been done?

The other possible solution is to expand the predefined set of user-visible keys for [message.android](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidnotification), to include `group` and other `NotificationCompat` properties where possible.

To summarise, the two pain points I think there is at the moment with Android is:
- the options allowed via [message.android](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidnotification) is limited.
- no ability to intercept the notification before it's shown when the app is in background

## How would you use it?

Tell us how you'd use this feature in your app.

This feature would allow users of this library to send notification messages and customise the notification before it's finally sent to the system tray.

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.