Android Firebase notifications are not sent to your registered message service when your application is in the background and your notification contains a notification key. To ensure that your service always processes notifications, do not use the notification field. Instead, use the data field for this purpose.
In fact, one drawback of using the Firebase notification field is that you cannot specify large and small icons for notifications in the system tray. It allows you to install only one icon.
Please note that this is not a โuniversalโ solution, as iOS users will not receive a notification in the background if there is no notification field.
Having said that, I believe that the best solution right now is to send you Android users a notification of the following type:
{ "to":"tHt4D...", "data": { "title":"Nice title", "body":"Nice body" } }
and process it in your service as follows:
public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> data = remoteMessage.getData(); makeMyCustomNotification(data.get("title"), data.get("body")); }
For iOS users, the standard way:
{ "to":"tHt4D...", "notification": { "title":"Nice title", "body":"Nice body" } }
This section has a great discussion here.
source share