gluonhq/substrate

Push notifications don't forward payload to RuntimeArgs if app was closed

Closed this issue · 1 comments

On Android, after receiving a push notification sent from the Firebase console/server, if the app is closed and the user taps on the notification, the apps gets opened (as expected), but the payload from the notification gets lost.

PushNotificationActivity doesn't work anymore, but MainActivity::onCreate is able to retrieve such payload with just:

Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v(TAG, "onCreate start, using Android Logging v1");
        System.err.println("onCreate called, writing this to System.err");

+        if (getIntent().getExtras() != null) {
+            for (String key : getIntent().getExtras().keySet()) {
+                Object value = getIntent().getExtras().get(key);
+                Log.d(TAG, "Key: " + key + " Value: " + value);
+            }
+        }
...

That produces:

[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: google.delivered_priority Value: high
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB]Key: google.sent_time Value: 1730144297078
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: google.ttl Value: 2419200
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: google.original_priority Value: high
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: google.product_id Value: 133506909
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: from Value: 435938649177
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: body Value: my_text
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: title Value: my_title
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: google.message_id Value: 0:1730144349038847%de0741a4de0741a4
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: gcm.n.analytics_data Value: Bundle[mParcelledData.dataSize=352]
[Mon Oct 28 20:39:15 CET 2024][INFO] [SUB] Key: collapse_key Value: com.gluonhq.pushnotes

So by filtering the fields related to the notification from the extras, this payload can be passed down to RuntimeArgs, like:

System.setProperty("Launch.PushNotification", getIntent().getStringExtra("title") + ", " + getIntent().getStringExtra("body"));

The four expected fields in the payload will be the same as those four used in PushFcmMessagingService:

HashMap<String, String> payload = new HashMap<>(remoteMessage.getData());
        payload.putIfAbsent("id", "");
        payload.putIfAbsent("silent", "false");
        payload.putIfAbsent("title", "");
        payload.putIfAbsent("body", "");

Expected Behavior

Current Behavior

Steps to Reproduce

Your Environment

This is better tackled directly in the PushNotifications service.