mirzemehdi / KMPNotifier

Kotlin Multiplatform Push Notification Library targetting android, iOS, Desktop and Web (JS and Wasm)
http://mirzemehdi.com/KMPNotifier/
Apache License 2.0
340 stars 19 forks source link

ANDROID: PayloadData is always empty onNotificationClicked when app is in foreground/background #73

Open jvondermarck opened 2 months ago

jvondermarck commented 2 months ago

@mirzemehdi When the app is in background (and even when the app is foreground, I also tried to be sure) so when I click on the notification, the method onNotificationClicked is triggered and the payload data is empty.

It happens to me in Android and I did set up everything in my MainActivity.kt so I do not know why it happens... And before clicking on the notification, the method onPayloadData is also triggered and my PayloadData is full.

I saw on another issue that it happens to someone and you fixed the issue in the 0.6.0 version. So I am sorry if I did something bad but I paid attention to what you wrote in your documentation.

jvondermarck commented 2 months ago

The workaround I found is that in my class when I listen to the different methods, I set a variable like private var latestPayload: PayloadData? = null and inside the method onPayloadData I set my variable latestPayload to the data variable from the parameters, so that when I trigger the method onNotificationClicked I can get my payload data from my custom variable and not from the data parameter that is empty. :)

mirzemehdi commented 1 month ago

Thank you for workaround @jvondermarck. But it should work without any workarounds actually. Can you please attach your full payload data that is printed on logs?

Also these should be called on launcher activity:

override fun onCreate(savedInstanceState: Bundle?) {
   super.onCreate(savedInstanceState)
      NotifierManager.onCreateOrOnNewIntent(intent)
      ...
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        NotifierManager.onCreateOrOnNewIntent(intent)
    }