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

Notification.clicklistener on cold start #2268

Open
mtaran89 opened this issue Mar 6, 2025 · 3 comments
Open

Notification.clicklistener on cold start #2268

mtaran89 opened this issue Mar 6, 2025 · 3 comments

Comments

@mtaran89
Copy link

mtaran89 commented Mar 6, 2025

Hi,
I have implemented the OneSignal Android SDK 5.1.29 and initialized it in the Application class. I want to handle the additional data in push notifications. When the app is in the foreground or background (running), the notification.clickListener is triggered. However, when the app is not running (cold start), clicking on a received notification does not trigger the notification.clickListener.

How can I resolve this issue?

@michael-winkler
Copy link

I think it would be better for the developers to see a code snippet from your implementation.

It's hard to find a issue without implementation details.

@mtaran89
Copy link
Author

mtaran89 commented Mar 6, 2025

OneSignal.getDebug().setLogLevel(com.onesignal.debug.LogLevel.DEBUG);
OneSignal.initWithContext(this, APP_ID);
OneSignal.getNotifications().addClickListener(
                iNotificationClickEvent -> {
                    try {
                        JSONObject JsonObject = iNotificationClickEvent.getNotification().getAdditionalData()
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                });

This code is inside the onCreate method of the application class.
The addClickListener callback is not triggered when clicking on incoming pushes while the app is closed.
It just triggered for clicking on incoming pushes when the app is open.
How can I retrieve the additional data from a push notification when the app is closed?

@jinliu9508
Copy link
Contributor

Hello @mtaran89, your code looks correct. Typically, the callback will fire and run your code whether the app is running or not. Were you using the debugger while testing your app? It’s possible that the debugger was disconnected and couldn't break at the right point. I’d recommend printing a message in the click event to see if it’s being triggered. Let us know if the message is never printed upon click.

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

No branches or pull requests

3 participants