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.
@2ndGAB i have created my onMessageReceive() , that method just call when app in foreground this is my screenshoot
foreground notification (notification that i want)
background notification
- Just show the white background icon (even though my color parameter is works)
- not showing notification like in foreground

i just confuse of FCM behavior , Would be very helpful. Thanks.
@abdymalikmulky ok so if I understand well, when the application is in background, the Notification is received by the system tray and not your application. I never tried it so I cannot help you about the problem you have with your icon. I'm really sorry.
I'm not so experienced with FCM but the basics are the following.
When your application is in foreground, the notification and the data payload is received by onMessageReceive() as you do. When the applicaton is in background, there are 2 situations:
- You send a Notification only message and it's received in the system tray and displayed as you observe but your application is not informed about it.
- You send a Notification with a data payload like you do and the behavior is the one explained just above except that the data payload is passed to your application via the Intent you receive in your main activity when the user tap the notification which cause your app to be started.
But if you have time, I would be very interested that you try to create your notification in your application, based on data message only.
That suppose to send the message from Google Advanced REST Client 
Then you receive the data payload in onMessageReceive() as you certainly do already and you generate your notification from onMessageReceive() as you may do already but in case and just for a very simple test:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getData());
sendNotification("FCM message received");
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
I would be very interested to know if a notification is created when you send the message while the application is in background.

ic_stat_ic_notification is attached.
Is it possible to use GCM receiver and FirebaseMessagingService's onMessageReceived(RemoteMessage remoteMessage){..} both at the same time.
It appears to me that when I send notification from Firbase console and app is in background... in my code both GCM receiver and FCM notification is showed.
first, is the notification showing icon app, sound and other same as property that you set in onMessageReceived() ? second , how if the app was killed ? the notification still show "normally" ?
@abdymalikmulky yes... When App is in background firebase shows default notification as per documentaion.
In my code I have kept both GCM receiver and FirebaseMessagingService. My problem is when I send message from firebase console it invokes GCM receiver as well as Firebase notification.
thank you @KishorAndroid , i will try it
@abdymalikmulky I have same issue ...When you can solved then please Tell Us!!
and How to set BigPictureStyle() in FCM notification when app is in background or Destroyed!!
Why is this issue closed? Since the main issue was about "Custom Notifications when app is in background or killed" and not solved yet? Does this mean we should not wait for a fix to this? I was really hoping Firebase team to be working on this.
@yayaa I think you need to read all the thread first. It's definitely not a bug and everything is working as planned
I know it is as planned, but i thought at least this would be considered as feature demand. Most of the applications icon's somehow has a background, and when firebase applies white tint on it to display as notification icon, it is mostly white squared empty icon or some non-sense icon there. At least, customisation on icon - color and so on. I see on notification message documentation there are some fields like that and i thought maybe it's already done and i missed that, but when i try to send that from console as additional params in advance section, i saw no changes. That's why i actually said no improvements on this topic. @Svoka but thanks anyway.
@yayaa oh, I think I get it now. In my case I don't need console at all, because we have server with this logic. So we send data-only messages. (Console still can't do this, I guess) By the way, you can provide icon from console: it's R.drawable.#_ICON_STRING#
I know with data messages you can do anything. But we talked about having notification messages sent from console would also be customizable. And then i saw that issue was closed... :(
@yayaa I guess we need to create separate issue for that :) In context of possibility to show icon this issue is closed.
Create new issue https://github.com/firebase/quickstart-android/issues/139
@Svoka Can you confrm that you build your application with Android Studio 2 to receive data only messages to background application?
@yayaa I don't think if I undertsand you well but if your are talking about icon appearing on status bar when you receive a notification, they are mandatory white on transparent background since Lollipop. This icon is set like that:
Notification.Builder..setSmallIcon(android.R.drawable.my little_icon)
Yes, i am aware of that @2ndGAB . But the problem here is when you have an icon with some graph on a solid background, and when firebase automatically creates your notification icon by tinting your application icon as white, it ends up like @abdymalikmulky screenshot.
Anyway since this issue is closed, i will just stop watching until i need to use Firebase again, and just hope them to fix it by then.
@yayaa That's very strange, here is how I create my notification from a data only message, received in onMessageReceived()
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_logo_notif)
.setLargeIcon(bm)
.setContentTitle(title)
.setSound(ringURI)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg).setSummaryText(this.getString(R.string.label_service)))
.setContentText(msg)
.setContentIntent(contentIntent)
.addAction(R.drawable.ic_action_place, null, geoPendingIntent)
.addAction(R.drawable.ic_action_web_site, null, webPendingIntent)
;
And here is the result: first the
And here is when you open
You can see that if you provide a valid little icon with setSmallIcon(), you won't have a white square in the status bar, same if you provide a valid large icon with setLargeIcon().
I usually build my icons with
I want to send a image in push message using firebase consol how can i send image in push message any solution.and also i want to custom look of notification..?
I want to send a image in push message using firebase consol how can i send image in push message any solution.and also i want to custom look of notification..?
I send User segment push notification but All user don't get push notification Why all did not get? From console.firebase.google.com I found monthly active user 4100 but when i send notification It shows 2100 send. and every time i got notification in 7 to 10 phones out of 12 different phones. That mean 50% user found notification. then what would be be others.

