Reputation: 346
As per the FCM documentation on Android Message Handling, push notifications will only be displayed if the App is backgrounded. It is not possible for a notification to appear in the System Tray while the App is foregrounded.
However! I have an app built with Capacitor. The app is currently on beta using the Internal Testing tool suite of the playstore. On it, when sending push notifications, I receive them through the onMessageReceived
callback AND the System Tray even when the app is foregrounded.
According to the documentation, that shouldn't be possible. So, I thought maybe (without being able to confirm):
onMessageReceived
get triggered)An example of the FCM message package I'm sending using the firebase-admin
SDK (latest version). This is a notification message with the optional data
payload provided:
{
data: { // data },
notification: { title: "My title", body: 'My body' },
android: { notification: { priority: 'max', visibility: 'public' } },
apns: { payload: { aps: [Object] } },
tokens: // token
}
Some observations:
firebase-admin
SDK (that was using the now-closed legacy APIs) to the latest version of the SDK. Before, I didn't have this kind of issues.android.notification.priority
and .visibility
props, but I get the same issue.Upvotes: 1
Views: 218
Reputation: 3665
If you need to get onMessageReceived
when the app is in foreground and background, You should send notification object as null and use data object for sending data as follows
{
data: { title: "My title", body: 'My body' },
notification: null,
android: { notification: { priority: 'max', visibility: 'public' } },
apns: { payload: { aps: [Object] } },
tokens: // token
}
Upvotes: -1