Cordova-plugin-firebase: Open application without tap notification, callback doesn't fire

Created on 9 Jul 2018  路  7Comments  路  Source: arnesson/cordova-plugin-firebase

Hi all,
the scenario is this:

  • App in background or closed completely.
  • I receive a notification on device, but I don't tap on it.
  • I open App normally (taping on its icon).
  • Callback 'onNotificationOpen' not fire and I don't receive notification's data.

Tested on Android 4.4 and 8.0.
So, how I can get notification's data when user does this?

help wanted question wontfix

All 7 comments

I believe the callback onNotificationOpen only fires when the user taps on a notification while the app is closed/background, or when the notification is pushed to the device while the app is open/foreground (and in this case, the native notification UI doesn't show - only the callback fires).

Hi @rwoody,
yes callback works in both cases you described, but this is a limit because sometimes the user opens app directly after sees notification (without tap notification). I also saw that after the app has been opened manually, if I tap on the notification nothing happens (callback doesn't fire). I will try to modify the plugin API to do this.

But how do you know the user wants to see the notification after directly opening the app? Are you relying on the push notification to update some state? The notification is up to the user to decide if they want to view, ignore, or delete it.

It seems like what you want might be a function to retrieve all unread delivered notifications, like the ones the newly added clearAllNotifications function removes.

Like on whatsapp, you can open the app without tap notification and you see new incoming data:
I saw that when arrives a new notification, if I put the smartphone offline and open the app, I already see the new data. So how can I get notification payload (if there is a notification) when open the app?

You need to sync/send the data another way. Push notifications are not a way to update your app in real time, and from what I've seen in most Cordova push notification libraries, you cannot read pending notifications when your app is in the foreground.

What you could do is use something like Firebase and store Alerts/Notifications in a collection, and send new push notifications when new items are added to the collection, either using local notifications or a library like this. That way you have much more control over the notification and any possible status you might want to track for a notification.

I'm not completely sure about this but Android has a method called getActiveNotifications which could be the one you are looking for. Here you have the docs link: https://developer.android.com/reference/android/service/notification/NotificationListenerService#getActiveNotifications()

I mean I'm not sure because I don't know if the Notification object retrieved by this array is similar to the one that we have with this plugin in order to access to the notification data (key/value pairs).

Hope it helps! I'm looking for a similar behaviour in my app so I will be looking out for updates

Edit: the problem here could be if you expects to trigger an event inside your callback and the user has deleted the notification from the device's panel (I asume you want your app to do this just like mine).

closing as this appears to not be fixable via the plugin

Was this page helpful?
0 / 5 - 0 ratings