-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Notifications when app is in background or killed #4
Comments
@ckarthikv could you clarify this question a little bit? Are you trying to show different notification styles when your app is in the background versus when your app is running in the foreground? |
Hi, |
@samtstern - Yes, we wanted to implement custom notification styles like Big Picture style, etc, when the app is in background or when the app is killed. I believe the notifications would be working through a broadcast receiver? Would be great if you could point me in the right direction so that one could intercept all kinds of messages (probably by extending the FirebaseBroadcastReceiver class) - whether the app is in background or killed, so that we could customize every aspect of the notification styles immaterial of the app state. |
Same problem. The icon being used is not what I want. Any help? |
@ckarthikv you can see this example of FirebaseMessagingService which is where your app can receive FCM messages and react. This is a good place to create notifications. Telling if your Activity is in the foreground (and reacting differently) can be a little tricky. My favorite way is to register a local You can see an example of this (using GCM, but the logic is the same for FCM) here. |
@frostymarvelous when you send a notification from the Firebase console is uses your app icon by default, and the Android system will turn that icon solid white when in the notification bar. If you are unhappy with that result you should implement FirebaseMessagingService and create the notifications manually when you receive a message. We are working on a way to improve this but for now that's the only way. |
@samtstern Both comments are incorrect. Custom messaging service is only called when the app is in the foreground. Android does not turn the icon white. It keeps its color. I've already implemented FirebaseMessagingService for my app when it's in the foreground. I don't understand why the notification is created automatically when FCM is meant to replace GCM. It is totally incompatible with the current flow. |
@frostymarvelous the behavior you are seeing sounds like a bug, in my apps the FirebaseMessagingService is definitely called when the app is in the background. As far as the icon color, on recent versions of Android the system applies a white mask to the icon. What sort of device do you have and what version of Android is it running? |
An S6 running 5.1.1. I think your behavior is the bug. From the docs "When your app is in the background on a user's device, notifications are On Fri, May 20, 2016, 7:29 PM Sam Stern [email protected] wrote:
|
Sorry @frostymarvelous I misunderstood your situation, you are correct. When you send a notification from the Firebase console and your app is in the background it cannot be customized. If you want custom background notifications you should use the FCM API to send data messages to your app and handle them in the FirebaseMessagingService where you can decide how the notification should look. |
If that works, then I'm good. Thanks a lot for your help. On Fri, May 20, 2016, 8:30 PM Sam Stern [email protected] wrote:
|
@frostymarvelous ok thanks for your patience while I figured out what was going on. Please feel free to open issues if you try this approach and have questions. Good luck! |
@samtstern I can't find an example of FCM API and how to manage the custom icon. |
Here is the documentation for sending Notification messages. The |
@samtstern thank you for the doc link, really helpfull. Console has custom params when sending a message, |
It will only work if your app is in the foreground. Otherwise, you have to On Tue, May 24, 2016, 7:48 PM Artem Osipov [email protected] wrote:
|
As far as I am aware it is not possible to customize the icon through the On Tue, May 24, 2016 at 12:48 PM Artem Osipov [email protected]
|
The key value pairs currently available in the Firebase composer are for data message values only. |
Do we need to customize it through console? Can't we just add it as a Once again, thanks for the great job you all are doing! On Tue, May 24, 2016, 8:47 PM Sam Stern [email protected] wrote:
|
It would have to be through the console since the client side handler does not reference any of your specified remote config parameters. |
Well, I thought that would work through the Configuration in the On Tue, May 24, 2016, 9:51 PM Arthur Thompson [email protected]
|
I'm having a similar issue getting the notifications customized. I'm not using the console at all - only making API calls. When app is in foreground notifications get handled by my custom FirebaseMessagingService, but when app is in the background notification displays solid white icon and ignores any specified payload support parameters (icon, color etc). Please advise whether this is expected as the behaviour appears to contradict comments made in this thread as well as #8 |
@DespisedIcon I had the similar problem, but it was my mistake I set it in the data section and it must be in the notification.
|
@Svoka Thanks for the tip. I've moved the icon parameter into the notification and now I'm getting the message
This same icon (R.drawable.ic_stat_logo) is being used for foreground notification builder without any issues.
Any idea why Firebase cannot resolve the icon for background notification? |
@DespisedIcon could you add your http request here maybe there is an issue with the formatting. |
@kroikie You were right. I've tracked down this issue to malformed notification data in the request. Icon and color working correctly now. Thanks |
@Svoka thats work form me... but only for small icon... any idea for large icon? |
@sir-gon if you don't specify the custom icon, FCM will use the app icon. |
Two years passed and we still dont have solution for this ? My app built using ionic 3, and it can receive the notification message just fine through FCM when the app is closed/killed, But it can't show the data message received. Mean i can't customise the notification style. I can't show the picture, can't show the button, and can't give user custom action. Currently, user need to tap the notification in the tray, which will open the app, then only the second notification, containing the data message, appear. Is there really no way to directly push the notification with data messages when the app is killed ? |
Why this issue is closed?! BTW, about the first post, the user @CarmelRaj07 reacted with thumbs down emoji And I can tell [s]he reacted with thumbs up and heart too. what a mess!! [S]He did it again with all available emojis for thedumbtechguy's comment too. |
i has know how to handle this issue.
Mehdi Dehghani <[email protected]> 于2019年6月12日周三 下午2:24写道:
… Why this issue is closed?!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4?email_source=notifications&email_token=ABMS2DPHR7OWLM63HJ5A5DLP2CJCTA5CNFSM4CEJOTS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXPMBVI#issuecomment-501137621>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABMS2DOCUA2KGYXUYGOOSCDP2CJCTANCNFSM4CEJOTSQ>
.
|
@flyme2012 thank you, actually I found the solution. of course after posting my prev comment. |
I'm not sure if anyone has mentioned it, but of course it's possible to have custom notification! The only thing is that you should do it yourself! From the server, you only send the message
Then on Android side, you need to write your code for handling push notification. Basically what you can do is creating a notification, with Android example by Firebase, open the link to see the whole section. Getting message Payload example Line 43 in 375c1ae
Creating notification function (open the link to see sendNotification function) Line 114 in 375c1ae
|
hey @ckarthikv |
git clone https://gerrit.googlesource.com/gitiles |
(edit - shortened original post as it bordered on a rant, and while I tried to keep it polite I don't think it was productive) @samtstern @kroikie pardon the tags but I think my scenario is impossible, by design, with the current Android SDK, given this thread and #368, and I'm hoping to confirm that (and if possible, get any insights into the why of the current SDK design). I have a body of "legacy" existing notification payloads that get sent to both iOS and Android. For Android clients they were GCM originally, migrated to FCM, and on FCM they include a notification payload - so from an FCM standpoint, they are "notification messages with a data payload". Historically this has been fine, as these were very simple "title/body" type notifications, but I want to start making them "richer". In order to start using Android rich notification features like styles and inline actions, I think my only option is to remove the notification payload and make these data-only. However, that's an expensive change for my team as the current notification templates are live "in the wild" with existing clients, so it's a breaking change (existing clients would stop showing the messages), so there needs to be a complicated transition/versioning story for the Android notifications delivered by our web service. There seems to be clear developer desire for a way to handle this scenario purely with Android app code and no web service changes, given the two issues in this repo (plus all their dupes) and several high traffic StackOverflow posts. FWIW this issue on the SDK covers the effective feature request here, but I don't see any discussion or responses in the last year - really all a dev needs is some way to tamper with the FCM message body before the SDK handles it, similar to a Notification Service Extension on iOS. That'd allow an app to "opt out" of the automatic SDK behavior on a per-notification basis, by deleting the notification payload if necessary, and not break existing app versions that might rely on it: firebase/firebase-android-sdk#2639 |
This will only work when app is foreground , when app is killed or in background it will not work |
Solution Please |
Hi,
I'd like to implement custom notification styles when app is in background or is killed. Is there a Firebase broadcast receiver class one could extend to implement the same? Would be very helpful. Thanks.
The text was updated successfully, but these errors were encountered: