Search code examples
androidfirebasefirebase-cloud-messagingmaui

FCM topic received all messages except the one that was subscribed to


I am using https://dev.to/serhii_korol_ab7776c50dba/creating-push-notifications-for-android-in-net-maui-2ak4 sample for send FCM messages with specific topic.

FirebaseMessaging messaging = FirebaseMessaging.GetMessaging(app);
var message = new Message()
{

      Topic =  "my_topic123",
      Data = _Data, 
      Android = new AndroidConfig { Priority = Priority.High },
}

string response = await messaging.SendAsync(message);

The problem is that I receive all topics no matter if register for another: FirebaseMessaging.Instance.SubscribeToTopic("my_topic"); What I need to perform to receive only specific topic which I subscribed?


Solution

  • Each client can be subscribed to multiple topics, so subscribing to another topic doesn't automatically unsubscribe what you consider the "current" topic.

    Once you subscribe a client to a topic, it receives messages for that topic until you unsubscribe the client. From the documentation on subscribing to a topic:

    To unsubscribe, the client app calls Firebase Cloud Messaging unsubscribeFromTopic() with the topic name.

    From a quick look at the source code, it looks like you'll need to uyse UnsubscribeFromTopicAsync in .NET.