Negation in condition while sending FCM message

It looks like Firebase supports this now! Firebase send-message

You can include up to five topics in your conditional expression, and parentheses are supported. Supported operators: &&, ||, !. Note the usage for !:

!('TopicA' in topics)

With this expression, any app instances that are not subscribed to TopicA, including app instances that are not subscribed to any topic, receive the message.


You can only target users based on whether they're subscribed to a topic, not whether they are not subscribed.

Since wildcard matching is only available in Firebase Notifications (for which a public API does not yet exist) and the console can only send notification messages (which indeed are handled by the system if the app is not in the foreground), your options will be limited to work arounds.

A few I can think of:

  1. track the version of the app that each user/device ID has installed in a Map<Token, Version> like structure. You could use the Firebase Database for that.

  2. enumerate all old versions and target those with a notification.

  3. send a data message with an announcement of a new release to everyone (through the Cloud Messaging API) and then suppress displaying of the message in onMessageReceived() if they already have the latest version.

Hmm... in hindsight #3 seems like a fairly clean solution. You're over-sending, but the system can handle that and as long as the frequency is not too high, most likely your users won't be affected too much.


Out of the box topics does not support operation like "people not subscribed to xxx".

However for your usecase (send notification to users that haven't updated), I would suggest to use Firebase Notification (not to confuse with FCM, firebase cloud messaging), you can find the doc here.

The key point is that in firebase console you can filter targets by app version. See the screenshot below of that particular part of the doc. I've tested it multiple time in production myself and it works greats. enter image description here