Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jperedadnr opened this issue Oct 29, 2024 · 0 comments · Fixed by #407
Closed

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

jperedadnr opened this issue Oct 29, 2024 · 0 comments · Fixed by #407
Assignees

Comments

@jperedadnr
Copy link
Contributor

jperedadnr commented Oct 29, 2024

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.

In this case, 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

And instead of using MainActivity, a BroadcastReceiver can be registered within the PushNotification service to get the intent and its extras, and then, by filtering the fields related to the notification from the extras, this payload can be passed down to RuntimeArgs.

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", "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant