Custom push notification receiver with FCM and Unity

1,432 views
Skip to first unread message

Lior Tal

unread,
Apr 21, 2019, 10:41:18 AM4/21/19
to Firebase Google Group
Hi all,

Due to GCM between phased out, we are looking to migrate our Unity based game to use FCM.
Our current infrastructure was using GCM with a BroadcastReceiver and an IntentService on android that would handle catching the push data and creating a Notification from it.

After integrating the FCM plugin for Unity, these no longer work, as it seems that FCM is handling all of this on its own.

Is there any way for us to provide a custom implementation as before? For example, we would like to support different use cases such as:
  • Deep linking into our game
  • Custom building of specialised notifications (e.g: with different visuals)
  • and more
Is there any way for us to customize the behaviour we're getting "out of the box" with the FCM plugin for Unity ?

Thanks,
Lior

Patrick Martin

unread,
Apr 23, 2019, 12:50:34 PM4/23/19
to Firebase Google Group
Hi Lior!

Deep links are supported, and you can read about how to set them up at our documentation page on the subject. The key point is making sure you update your AndroidManifest.xml to support the links.

In Unity, rather than using a BroadcastReceiver and IntentService, you're able to register a handler for the Firebase.Messaging.FirebaseMessaging.MessageReceived event. You can see more details here, and a breakdown of when this handler is invoked is available here. The key takeaway is that, whenever your app is in the foreground, the MessageReceived callback is invoked and you have to take care of notifying the users yourself. When your app is in the background, data messages will hit the callback for you to take action on whereas notification messages will display notifications on their own without your input.

Let me know if that works out for you. If you'd like some the ability to customize the notification template, I would love it if you could make a feature request here.

--Patrick

Alex Ames

unread,
Apr 23, 2019, 2:56:13 PM4/23/19
to fireba...@googlegroups.com
Hi Lior, 

You're correct that by default FCM handles much of the heavy lifting that is needed to handle incoming events and populate Notification data.

In addition to what Patrick said, you can override this default behavior by customizing the entry point of your app, allowing you to intercept incoming Intents and do custom handling on them before passing them along to Unity. You can see how this can be done here:


You can also make a custom message handler by following the instructions here:




--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/ebfed50f-10bc-4b1a-a80d-718a51570cdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lior Tal

unread,
Apr 24, 2019, 10:14:09 AM4/24/19
to Firebase Google Group
Another reason to want to customize this is that we are using 2 different 'sources' for generating push messages (our backend and Mixpanel).
Since Mixpanel uses it's own payload format, these messages are never posted as Notifications for the user to see.

This can be solved by a custom implementation of FirebaseMessagingService, but since the Unity plugin already has this implementation and since it declares such a service (in the android manifest) to handle these events, a second service cannot be created.

It could be nice to be able to use the Unity plugin while providing our own implementation of that service.

Right now, we have spent a few days of work before discarding everything and integrating the (native) android SDK.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.

Lior Tal

unread,
Apr 24, 2019, 10:15:13 AM4/24/19
to fireba...@googlegroups.com
Another reason to want to customize this is that we are using 2 different 'sources' for generating push messages (our backend and Mixpanel).

Since Mixpanel uses it's own payload format, these messages are never posted as Notifications for the user to see.

This can be solved by a custom implementation of FirebaseMessagingService, but since the Unity plugin already has this implementation and since it declares such a service (in the android manifest) to handle these events, a second service cannot be created.

It could be nice to be able to use the Unity plugin while providing our own implementation of that service.

Right now, we have spent a few days of work before discarding everything and integrating the (native) android SDK.

Stewart Miles

unread,
Apr 24, 2019, 11:18:29 AM4/24/19
to Firebase Google Group
Lior, as Alex pointed out.  The Firebase Unity plugin includes it's own default messaging service which can be overridden in your AndroidManifest.xml.  It's a shame you had to build your own solution when the documentation points out you can do the following to override the service
<service android:name="com.google.firebase.messaging.cpp.ListenerService"
         
tools:node="remove" />
<service android:name="com.google.firebase.messaging.cpp.samples.MyListenerService"
         
android:exported="false">
 
<intent-filter>
   
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
 
</intent-filter>
</service>

Reply all
Reply to author
Forward
0 new messages