Unity-Firebase-messaging issue

HI,

Facing an issue with Firebase-messaging integration. For notifications I used firebase_unity_sdk - FirebaseMessaging. If I send message as a “notification” everything is working fine as per the documentation. If I send message as “data”, as per the documentation OnMessageReceived should call irrespective of application state(background or foreground or closed). But OnMessageReceived is getting called only if application is foreground(open state). Can you please help me in this.

  1. JSONObject json = new JSONObject();
    json.put( “to”, userDeviceIdKey.trim() );
    JSONObject info = new JSONObject();
    JSONObject data = new JSONObject();
    info.put( “title”, “Notificatoin FCM” );
    json.put( “notification”, info );

Above one is working fine , getting simple notification when application is closed or background and OnMessageReceived is getting called if app is in foreground.

  1. JSONObject json = new JSONObject();
    json.put( “to”, userDeviceIdKey.trim() );
    JSONObject info = new JSONObject();
    JSONObject data = new JSONObject();
    data.put( “title”, “data FCM” );
    json.put( “data”, data );

When I send above one (02), OnMessageReceived is not getting called if application is closed or in background.

This is my code :

public void Start()
{
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
Debug.Log("Firebase token " + token.Token);
}

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{
Debug.Log("Firebase onMessageReceived ");
}

Thank you,
Ranadheer

I am not familiar with Firebase and the exact plugin you’re using, but on some platforms, if the app is not in the foreground it will not execute anything, including the code for handling any incoming messages.

Below link is having example.

Notifications I am able to receive and working fine. But for Customized notifications I want to create my own notification system. for that I am sending “data” payload from the server. OnMessageReceived method should catch that as per the documentation. But not getting triggered.

I am really not familiar with that… i offer private consultation (paid), if that is something you’d like to do you can PM me.

Thank you, I will reach out to you.

Make sure you have android activity updated and
MessageForwardingService
service added to android manifest as described here یک برنامه مشتری Firebase Cloud Messaging با Unity راه اندازی کنید

For me OnMessageReceived called when sending the notification from firebase console (checked the log while unity build is in foreground). But no notification is showing in the notification tray. How to enable that one.

AndroidManifest.xml as followed:

<?xml version="1.0" encoding="utf-8"?>

Thanks in Advance