Custom Notifications when app is in background or killed
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.
@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, When i tried to implement this notification i get error like Error:(28, 0) Plugin with id 'com.google.gms.google-services' not found.
@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. It is using the launcher icon while but the new guidelines require that we use a white on transparent icon. Also, the color is wrong. I can't seem to find any way to customize this looking at the available methods.
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 BroadcastReceiver in the Activity and then do a sendBroadcast from the service. You will get true from that method if your receiver is running (meaning your app is in the foreground), and false otherwise.
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. What we are asking for is how to handle it when it's in the background.
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 delivered to the system tray. When a user clicks on the notification, the app launcher opens your app. If you want, you can also add client message handling to receive notifications in your app when it is already in the foreground on the user's device."
On Fri, May 20, 2016, 7:29 PM Sam Stern [email protected] wrote:
@frostymarvelous https://github.com/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?
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/firebase/quickstart-android/issues/4#issuecomment-220697618
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. I thought it behaved the same across.
Thanks a lot for your help. If you're part of the team, then thanks for your hard work as well.
On Fri, May 20, 2016, 8:30 PM Sam Stern [email protected] wrote:
Sorry @frostymarvelous https://github.com/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.
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/firebase/quickstart-android/issues/4#issuecomment-220710992
@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. Do you have an example of this? I'm new to cloud messaging and I only find that there is a parameter icon, but no details how to implement it in my app Thank you!
Here is the documentation for sending Notification messages.
The icon parameter can be used to specify a drawable within your app. If you want to use R.drawable.foo, just pass foo.
@samtstern thank you for the doc link, really helpfull.
Console has custom params when sending a message, must the custom icon work there too? ( In my test this is still the app icon, but I can do something wrong)
It will only work if your app is in the foreground. Otherwise, you have to use the the api.
On Tue, May 24, 2016, 7:48 PM Artem Osipov [email protected] wrote:
@samtstern https://github.com/samtstern thank you for the doc link, really helpfull.
Console has custom params when sending a message, must the custom icon work there too? ( In my test this is still the app icon, but I can do something wrong)
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/firebase/quickstart-android/issues/4#issuecomment-221375176
As far as I am aware it is not possible to customize the icon through the console right now, but that is a high-priority feature for us going forward.
On Tue, May 24, 2016 at 12:48 PM Artem Osipov [email protected] wrote:
@samtstern https://github.com/samtstern thank you for the doc link, really helpfull.
Console has custom params when sending a message, must the custom icon work there too? ( In my test this is still the app icon, but I can do something wrong)
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/firebase/quickstart-android/issues/4#issuecomment-221375176
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 config parameter? Thanks would be better Don't forget the colors as well please?
Once again, thanks for the great job you all are doing!
On Tue, May 24, 2016, 8:47 PM Sam Stern [email protected] wrote:
As far as I am aware it is not possible to customize the icon through the console right now, but that is a high-priority feature for us going forward.
On Tue, May 24, 2016 at 12:48 PM Artem Osipov [email protected] wrote:
@samtstern https://github.com/samtstern thank you for the doc link, really helpfull.
Console has custom params when sending a message, must the custom icon work there too? ( In my test this is still the app icon, but I can do something wrong)
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub < https://github.com/firebase/quickstart-android/issues/4#issuecomment-221375176
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/firebase/quickstart-android/issues/4#issuecomment-221385340
It would have to be through the console since the client side handler does not reference any of your specified remote config parameters.