OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

Notification.clicklistener on cold start

Open mtaran89 opened this issue 11 months ago • 3 comments

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?

mtaran89 avatar Mar 06 '25 11:03 mtaran89

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.

michael-winkler avatar Mar 06 '25 13:03 michael-winkler

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?

mtaran89 avatar Mar 06 '25 13:03 mtaran89

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.

jinliu9508 avatar Mar 21 '25 17:03 jinliu9508

Closing due to no response. Please try the latest SDK and open a new issue if this is still a problem.

jkasten2 avatar Aug 11 '25 20:08 jkasten2