My experience and problems with Cloud Messaging and Unity

345 views
Skip to first unread message

francismoy

unread,
Feb 4, 2021, 5:16:16 AM2/4/21
to Firebase Google Group

I’m using Cloud Messaging (7.0.2) to send push notifications to my Android app together with rewards (as data) using the Notification Composer. The whole workflow has been a bit challenging, so I want to explain how I did it and check whether this is the intended API behavior. I’m using Unity 2019.4.10f1. 

1) When the game is not running at all and I tap on a notification, onMessageReceived is called with the data. However and since the data is also in the extras of the intent, I must remove these extras, otherwise, future calls to OnFocus without going to background would result in repeated rewards (more on this in point 4). By the way, I didn’t find this case well documented.

2) When the game is in foreground, everything is as expected: onMessageReceived is called with both the data and the notification and I can react accordingly. This case is the less problematic.

3) When the game is in background and I tap on a notification, onMessageReceived is not called, but the data is in the extras of the intent. So I need to place code in the OnFocus() Unity method and read the extras of the intent, removing these so that further calls to OnFocus() without going into background don’t repeat the reward (see point 4).

4) I’m not sure how Android manages intents, but I observed the following: if I move the app to background and then back to foreground, OnFocus() is called but it seems the intent, if it previously had any extras, is now empty. However, if I just make an in-app payment, when the Android payment processing screen is closed upon a successful/failed transaction, OnFocus() is called but the intent continues to have the extras of the intent, which might result in giving the same reward over and over if I don’t remove these extras once processed.

So am I understanding the workflow all right? Is the management of Android intents as expected?

martin...@google.com

unread,
Mar 23, 2021, 12:16:10 PM3/23/21
to Firebase Google Group
Hi,

This tracks a GitHub issue that we're currently tracking. If you upgrade to the latest version of the Unity plugin (currently 7.1.0) and follow the instructions in this answer, you should be able to work around this for now.

Sorry it took so long to respond,
--Patrick
Reply all
Reply to author
Forward
0 new messages