Need help handling foreground notifications on android in my capacitor app

Viewed 218

I created an ios/android app using reactJS and am currently trying to handle foreground notifications when the app is running on android.

Here's a little code snipped of how I'm currently handling the foreground notifications. It works for ios but not for android.

PushNotifications.addListener('pushNotificationReceived', function (notification) {
        console.log('notification was recieved in messageList: ' + JSON.stringify(notification));
        getMessages()
    })

this calls my getMessages() function when a message is sent to a user. When a message is sent, a notification is simultaneously sent so this works ok for now. Later i'll implement something better like firebase realtime database or something, to watch for changes.

I've imported "PushNotifications" from "@capacitor/push-notifications"

https://capacitorjs.com/docs/apis/push-notifications

Here in the docs there's a section called addListener(‘pushNotificationReceived’, …).

However for me this only works on ios and not android...

Anyone experience a similar issue?

Any advice on how to troubleshoot?

0 Answers
Related