Notification.clicklistener on cold start
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?
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.
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?
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.
Closing due to no response. Please try the latest SDK and open a new issue if this is still a problem.