Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to subscribe firebase push notifications topic from pcl

In my project, I am trying to implement topic-based firebase push notifications but facing an issue, unable to subscribe to the topic from OnButtonClick. In Android Solution Project, written like this in MainActivity.cs

FirebaseMessaging.Instance.SubscribeToTopic("news");

The above code working fine but I am trying to implement subscribe topics on button click.
Is there any way to subscribe notifications on button click?

Best Answer

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 9 Accepted Answer

    Use Messaging Center .

    Forms project

    void ButtonClicked(){
        MessagingCenter.Send<object>(this, "Hi");
    }
    

    Android project

     //Put it in OnCreate method.
    MessagingCenter.Subscribe<object> (this, "Hi", (sender) =>
    {
        FirebaseMessaging.Instance.SubscribeToTopic("news");
    });
    

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 9 Accepted Answer

    Use Messaging Center .

    Forms project

    void ButtonClicked(){
        MessagingCenter.Send<object>(this, "Hi");
    }
    

    Android project

     //Put it in OnCreate method.
    MessagingCenter.Subscribe<object> (this, "Hi", (sender) =>
    {
        FirebaseMessaging.Instance.SubscribeToTopic("news");
    });
    
Sign In or Register to comment.